I am trying to perform a quick search but I keep getting this error or a similar one
Cannot perform 'LIKE' operation on System.Int32 and System.String
I have a textbox, a find button, and 6 radio buttons. The search is performed on the columns in my database depending on which radio button is selected. I am having trouble when I try passing the type int columns. This is the section of code I am having problems with.
DataRow[] foundRows;
UserTable.DefaultView.Sort="TaxNumber";
foundRows = UserTable.Select("TaxNumber LIKE '" + txtFind.Text+"*'");
I also tried: foundRows = UserTable.Select("TaxNumber LIKE '" + int.Parse(txtFind.Text)+"*'"); but that didnt work either.
Thanks
sanjeewa darshanaPosted Sep 8, 2012, 6:07 AM
NupurPosted Apr 24, 2009, 12:50 AM
Dusan TkacPosted Dec 17, 2008, 8:33 AM
Hi,
you are getting this error because the Type of your "TaxNumber" column in the data table is Int32 and you are trying to compare it with string. I think that LIKE can be used only to compare two strings.
Try this:
foundRows = UserTable.Select("Convert(TaxNumber, 'System.String') LIKE '" + txtFind.Text+"*'");
Cheers,
Dusan
MariaPosted Dec 16, 2008, 3:35 PM
Ryan AlfordPosted Dec 16, 2008, 3:24 PM