Tuesday, October 2, 2018

Trim method does not exist on integer?

No kidding, you cant trim and integer. Something interesting happened today that I cannot seem to wrap my head around. Keep in mind this is existing code, being used by hundreds of users. All of the sudden (on my development machine only, this is not happening on any users device) I started getting this error on a form where a datagrid is placed. I have a loop where I am access columns in a row like this:

Dim sumValue as String For Each Row as DataRow in rowArray sumValue = Row.Item("my_column").Trim Next 

The rowArray is a table of data filled from a view in my database. I can confirm that there is no casting to type int in the data access. I can confirm that "my_column" is of type VarChar in my database. The value of that field when the error occurs is "27821", which yes is an integer but again THIS CODE HAS NOT BEEN TOUCHED IN YEARS. Users are and have been using this code daily with no issues.

This is a simple fix and in fact I should have probably been accessing these columns like this in the first place:

sumValue = Row.Item("my_column").ToString.Trim 

I just don't understand why all of the sudden this column is being cast as an integer. Something to note is that the table where "my_column" is being filled from is full of strings that are integers. The column has data like 60, 75, 150, 200, ect. Never any problems.

Trim method does not exist on integer? Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team