Search code examples
datasetasp.net-2.0

Filtering dataset with condition


I am using asp.net 2.0 and c#.

I have a dataset, which is getting the employee info. Now I want to filter the gridview based on a name that the user has put in the search textbox.

I am doing this:

DataSet ds = new DataSet("EmployeeInformation");
//........ loading DataSet ds with emploee info
string strExpr;
strExpr = "Name LIKE %" + txtSearchEmployee.Text.Trim() + "%";
ds.Tables[0].Select(strExpr);

I am getting an error in the last step, that the operator is missing.

Please guide me how can I achieve this. Thanks in advance.


Solution

  • You just need to add single quotes around your LIKE criteria:

    strExpr = "Name LIKE '%" + txtSearchEmployee.Text.Trim() + "%'";
    ds.Tables[0].Select(strExpr);