How to use LIKE on int column?
Posted on 2006-04-20
I have a text box that users can type in a PersonID (all integers) and get a match of IDs in a datagrid. At least that is the concept. The problem is that I keep getting errors related to "Cannot perform LIKE operation on System.Int32 and System.String" or something similar depending on how I rearrange the datatable column data type and the filter expression.
I'm currently changing the integer column to a string hoping it can use LIKE.
ds.Tables.Columns["PersonID"].DataType = System.Type.GetType("System.String");
The above throws an exception because the column datatype can't be modified after it is filled with data. I'm using a data adapter to fill a data set so the table will always have data unless I get into creating the datatable from scratch, which I want to avoid.
Then I do this:
dt.DefaultView.RowFilter = "PersonID Like '" + txtPersonCode.Text.ToString() + "'";
and get the error. I want a user to type in 101 and get results such as 1010, 10122, 1011. How can I do this?