Reputation: 11
I have extracted data from an excel sheet to a datagridview which is great, but I have made a search box and I am unable to get it to work.
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
DataView dv = new DataView(dt);
dv.RowFilter = "Site Name LIKE '%" + textBox2.Text + "%'";
dataGridView1.DataSource = dv.ToTable();
}
}
I'm getting error on the dv.Rowfilter
saying
Syntax error: Missing operand after 'Name' operator.
Upvotes: 1
Views: 67
Reputation: 16389
String "Site Name" is not correct column name. You must be having something like "Site_Name" may be; just correct the same.
dv.RowFilter = "Site_Name LIKE '%" + textBox2.Text + "%'";
Alternatively, enclose the column name in square brackets like below:
dv.RowFilter = "[Site Name] LIKE '%" + textBox2.Text + "%'";
Refer this: http://www.csharp-examples.net/dataview-rowfilter/
Upvotes: 1