string   sql   =   "select   *   from   I_CustomOrder   where   1=1";  if(TextBox1.Text != "")
{  
sql += " and WRFAC='" + TextBox1.Text.Trim() + "'"; }
      
if(TextBox2.Text != "" & TextBox3.Text != "" )    { 
sql += " and (WRLOC like '" + TextBox2.Text.Trim() + "' or WRLOC like '" + TextBox3.Text.Trim() + "')  ";

}  if(TextBox4.Text != "" & TextBox5.Text != "")    {
sql += " and (WRPROD like '" + TextBox4.Text.Trim() + "' or  WRPROD like '" + TextBox5.Text.Trim() + "')  ";
}
if(TextBox6.Text != "" & TextBox7.Text != "")    {
  
sql += " and (WRTOOL like '" + TextBox6.Text.Trim() + "' or WRTOOL like  '" + TextBox7.Text.Trim() + "')  ";
}
if(TextBox8.Text != "" & TextBox9.Text != "")    {
  
sql += " and (WRRDTE  like '" + TextBox8.Text.Trim().ToString() + "' or  WRRDTE  like '" + TextBox9.Text.Trim().ToString() + "')  ";
}

解决方案 »

  1.   

    你这个like 竟然没有 通配符????
      

  2.   

    將sting 改為StringBuilder
    sql+改為sql.Append()
    StringBuilder sql   =  new StringBuilder( "select   *   from   I_CustomOrder   where   1=1"); if(TextBox1.Text != "")
     {  
      sql.Append( " and WRFAC='" + TextBox1.Text.Trim() + "'");
    }
          
      

  3.   

    SqlDataAdapter ada = new SqlDataAdapter(sql,con); 改了以后,引用sql后提示cannot convert from 'System.Text.StringBuilder' to 'string'
      

  4.   

    如果不需要还不如改成in
    在WRFAC上建索引  
      

  5.   

    要这样转换为 string sql=sql2.ToString();才能引用。那根直接用string有什么区别?
      

  6.   

    这样加通配符?like '%" + TextBox2.Text.Trim() + "%'