你这里有个bug。
如果strAccountNameKey=="",而strRealName!=""时那么你的代码就有问题了
变成sb =" and truename LIKE '%"+strRealName+"%'";
那么你执行时肯定就会出错因为你的RowFilter="and ......"那样就不对
你调试一下是不是这样,祝你好运!
如果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();
sb 是不是少写了where啊?