Filtering dataset with condition

大憨熊 提交于 2019-12-24 02:45:12

问题


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.


回答1:


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

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


来源:https://stackoverflow.com/questions/3178316/filtering-dataset-with-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!