views:

130

answers:

1

I have recently been tasked with upgrading an application from .net 1.1 to 3.5 and came across a RowFilter on a DataView that had a different behavior between the two versions.

Here is my code block in 1.1 that works in 1.1 but not 3.5. I get the following error trying to run this in 3.5 "Cannot perform '=' operation on System.String and System.Int32" Both the 1.1 and 3.5 are hitting the same database, I am just confused as to how 1.1 sees the string parameter and treats it as a string without having to put tic marks around it but in 3.5 it sees rptNum and requires you to put tics around it. The field in the dv is a string DataType.

 private DataView BuildDataView(string rptNum) {
  DataView dv = null;

  if(dt != null) {
   dv=new DataView(dt);
   dv.RowFilter="reporting_number = " + rptNum;
  }

  return dv;
 }

Here is my code block in 3.5 changed so that it works. I had to add tic marks around the string parameter so that it would treat it as a string.

 private DataView BuildDataView(string rptNum) {
  DataView dv = null;

  if(dt != null) {
   dv=new DataView(dt);
   dv.RowFilter="reporting_number = '" + rptNum + "'";
  }

  return dv;
 }
A: 

Given the error message:

"Cannot perform '=' operation on System.String and System.Int32

it sounds as though the value of rptNum causing the error is numerical (although the column of String type): just a guess, but maybe version 1.1 looks first at the value of the variable in the filter and is forgiving enough to process it if the filter clause can be interpreted as given by the user, whereas in 3.5 the type cast takes precedence. Do you get the an error message if rptNum is non-numerical when run in version 1.1 of your code?

davek
No I do not get the error message.
TampaRich
OK, that would suggest that type checking does not take place "up front" in 1.1, which seems to be the case in 3.5.
davek