string sql;
string sql2="where 1=1;
string key;
if(key!="")
{
   sql2=sql2 +"and a.corp_name='"+key+"'";
}
sql="select a.* from corp '+sql2+"'";为什么这样不对。

解决方案 »

  1.   

    sql="select a.* from corp a '+sql2+"'";
      

  2.   

    sql="select a.* from corp '"+sql2+"'";少了一个双引号
      

  3.   

    string sql;
    string sql2="where 1=1";
    string key;
    if(key!="")
    {
      sql2=sql2 +"and a.corp_name='"+key+"'";
    }
    sql="select a.* from corp "+sql2;
      

  4.   

    string sql;
    string sql2="where 1=1";
    string key;
    if(key!="")
    {
      sql2=sql2 +"and a.corp_name='"+key+"'";
    }
    sql="select a.* from corp a "+sql2;
      

  5.   

    还是不正确的话,把sql文贴出来让大家看看。
      

  6.   

    string sql2="where 1=1;也应该改成string sql2=" where 1=1 ";
      

  7.   

    我直接给你写下来  string sql2="where 1=1;   这少了一个引号,看见没。不细心啊,该打!!
      还有
    sql="select a.* from corp '+sql2+"'"; 在语句后面拼接sql不是这样写的。
    应该是sql="select a.* from corp as a "+sql2;
    还有啊,你前面写的 a.* 后面都没有a,你怎么查啊 corp as a,或者 corp a 不要as也可以就这样,一看楼主就是小鸟一个,好好努力,注重基础
      

  8.   


    using System.Text;string sql;
    StringBuilder sb = new StringBuilder();
    sb.Append("select * from corp where 1=1 ");
    string key;
    if(key!="")
    {
      sb.Append(" and corp_name='"+key+"' ");
    }
    sql=sb.ToString();
      

  9.   

    if(key!="")
    {
      sql2=sql2 +"and a.corp_name='"+key+"'";
    }
    这个好像也是错的。
    第一次能搜索到,第二次就修改不到了
      

  10.   

    string sql;
    string sql2="where 1=1";
    string key;
    if(key!="")
    {
      sql2=sql2 +"and a.corp_name='"+key+"'";
    }
    sql="select a.* from corp '"+sql2+"'";sql2干嘛用的?
     
      

  11.   

    问:"sql2干嘛用的?"
    答:"搜索用的"都是人才
      

  12.   

    你先把完整的sql的log打印出来,然后看看错误,你的字符串拼接有问题,而且string不全。看得人很晕