过滤数据集与条件 [英] Filtering dataset with condition

查看:181
本文介绍了过滤数据集与条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net 2.0和c#。



我有一个数据集,这是获取员工信息。现在我想基于用户放在搜索文本框中的名称来过滤gridview。



我这样做:

  DataSet ds = new DataSet 员工信息); 
// ........加载DataSet ds与emploee info
string strExpr;
strExpr =Name LIKE%+ txtSearchEmployee.Text.Trim()+%;
ds.Tables [0] .Select(strExpr);

我在最后一步收到错误,操作员丢失。



请指导我如何实现这一点。感谢提前。

解决方案

您只需在您的LIKE标准中添加单引号:

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


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.

解决方案

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

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

这篇关于过滤数据集与条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆