DataTable.DefaultView.RowFilter 过滤两个条件的连接方法

2025-02-23 06:18:50
推荐回答(3个)
回答1:

你这里有个bug。
如果strAccountNameKey=="",而strRealName!=""时那么你的代码就有问题了
变成sb =" and truename LIKE '%"+strRealName+"%'";
那么你执行时肯定就会出错因为你的RowFilter="and ......"那样就不对
你调试一下是不是这样,祝你好运!

回答2:

如果strAccountNameKey=="",而strRealName!=""时那么你的代码就有问题了
要变成变成sb =" and truename LIKE '%"+strRealName+"%'"
具体代码如下:
if (strAccountNameKey != "")
{
sb += " username LIKE '%"+strAccountNameKey+"%' ";
}
string strRealName = PageValidate.ReplaceStr(txtRealName.Text.Trim());//按姓名搜索
if (strRealName != "")
{
sb +=" and truename LIKE '%"+strRealName+"%'";
}
dds.Tables["a"].DefaultView.RowFilter = sb.ToString();

回答3:

sb 是不是少写了where啊?