日期:2014-05-18  浏览次数:20842 次

这样写不能判断空值吗
C# code
        private void DataLoad()
        {
            string strQuery = "";
            if (txtManagementId.Text.Trim() != "")
            {
                if (strQuery != "")
                {
                    strQuery = strQuery + " AND ";
                }
                strQuery = strQuery + " UserId LIKE '%" + txtManagementId.Text.Trim() + "%' ";
            }

            if (txtUserId.Text.Trim() != "")
            {
                if (strQuery != "")
                {
                    strQuery = strQuery + " AND ";
                }
                strQuery = strQuery + " UserNumber LIKE '%" + txtUserId.Text.Trim() + "%' ";
            }

            if (cboUserGrade.SelectedValue != "")
            {
                if (strQuery != "")
                {
                    strQuery = strQuery + " AND ";
                }
                strQuery = strQuery + " UserGrade = '" + cboUserGrade.SelectedValue + "' ";
            }
}
我定义了一个DateLoad要完成它的搜索功能

------解决方案--------------------
if (strQuery != "")
{
strQuery = strQuery + " AND ";
}

不知楼主为什么要做个这判断,如果为空的话,那你后面的语句再执行会报错的