risail
risail

Reputation: 537

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

Upvotes: 3

Views: 11615

Answers (1)

crthompson
crthompson

Reputation: 15865

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

Upvotes: 9

Related Questions