Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to filter/search some results from my existing DataGridView Table. I have done most of them except one field. That's the first field of my DataGridView Table "Product ID" it's an Int data type field. So I think it needs a bit conversion on the Int Value to System.String.. but I'm not getting how to fix that.. Can any one please help me..
C#
private void txtSearch_TextChanged(object sender, EventArgs e)
{
    try 
    {
        DataView DV = new DataView(dbdataset);
        DV.RowFilter = string.Format("Convert[Product ID, System.String] LIKE '%{0}%' OR [Product Name] LIKE '%{0}%' OR [Brand Name] LIKE '%{0}%' OR [Pro. Size ID] LIKE '%{0}%'", txtSearch.Text);
        dgView.DataSource = DV;
    }
     catch (Exception ex)
    {
        Error_txt.Text = ex.Message;
    }

}

It gives an error
Syntax error: Missing operand after '[Product ID, System.String]' operator.
Posted
Updated 13-May-14 19:15pm
v2
Comments
ZurdoDev 13-May-14 21:04pm    
If I recall a RowFilter is the same syntax as SQL. So, to convert, you do

CONVERT(NVARCHAR(50), [Product ID]) LIKE ...

Or, you may not have to convert at all. Sql will do some implicit conversions for you.

[Product ID] LIKE %{0}%

change
C#
Convert[Product ID, System.String] LIKE '%{0}%' 

to
C#
Convert([Product ID], 'System.String') LIKE '%{0}%' 
 
Share this answer
 
Comments
[no name] 14-May-14 3:59am    
DamithSL you are correct bro, now it will work. Thanks a lot for your support.
You can put row filter on this way
DV.RowFilter = string.Format("[Product ID]'{0}' OR [Product Name]='{0}' OR [Brand Name]='{0}' OR [Pro. Size ID]='{0}'", txtSearch.Text);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900