你现在“作为查询条件”是怎么写的,拼where条件?那为空的不拼进去就是了= =歪门邪道: 拼条件直接string.Format( " where '{0} in (编码,'')  ", txt.Text )

解决方案 »

  1.   

    var sb = new StringBuilder("SELECT * FROM TABLE WHERE 1 = 1");
    if(xxxx != string.Empty)
    sb.AppendFormat("AND XXXX LIKE '{0}%' ", xxx);
    ...
      

  2.   


    string sqlText = "select * from table where 1=1 ";
                if (!string.IsNullOrEmpty(name)) {
                    sqlText += string.Format(" and name='{0}'",name);
                }
                if (!string.IsNullOrEmpty(code))
                {
                    sqlText += string.Format(" and code={0}", Convert.ToInt32(code));
                }
                // 执行sql,,省略
      

  3.   

    就直接判断先 为不为空 。假设他们都空  那么where 是多余的对不对  你在sql里面 where 后面 多写一个条件 1=1,这样就可以避免这个问题了
      

  4.   

    动态拼接Sql,为空就不拼接。