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

Dusan Tkac46 reputationPosted Dec 17, 2008, 3:33 AM EST
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
Ryan AlfordRank #1,411 · 1.2K reputationPosted Dec 16, 2008, 10:24 AM EST
Maria71 reputationPosted Dec 16, 2008, 10:35 AM EST
Nupur2 reputationPosted Apr 23, 2009, 8:50 PM EDT
sanjeewa darshana2 reputationPosted Sep 8, 2012, 2:07 AM EDT