Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Cannot perform Like Operation on 'System.Int32' and 'System.String'" setting DataGridView data source

I have created a data grid view in a Windows application using Visual Studio and I am trying to query it with a search text box. The field is a series of numbers but I have it set up for Varchar(10).

When I use the command below I get the following error

Cannot perform Like Operation on 'System.Int32' and 'System.String'

Code:

DataView DV = new DataView(dbdataset);
DV.RowFilter = string.Format("JobNumber Like '%{0}%' ", textBox1.Text);
dataGridView1.DataSource = DV;

Thanks

like image 731
risail Avatar asked Mar 16 '26 12:03

risail


1 Answers

Cast the JobNumber to a string before you do a like.

DV.RowFilter = string.Format("convert(JobNumber, 'System.String') Like '%{0}%' ",
                             textBox1.Text);

DataViews can take many different options in their filters.

As explained here, the filtering is taking place by .NET and the DataView, not by MySql

like image 141
crthompson Avatar answered Mar 18 '26 01:03

crthompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!