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;
}