public DataSet getYGXXTJ()
        {
            DataBaseEx db = new DataBaseEx();
            DataSet ds = null;
            strint sql="";
            try
               {
                   sql=@"select A from ABC";
                         select B from ABC   
                          select C from ABC
                }
         }
我要想加个查询条件要怎么加啊?  比如说   我想  加上A!=“”  
  那下面直接   if(A!=“”)
              {sql += “and  A='+a+'”}  这样肯定不对  要怎么写啊   谢谢

解决方案 »

  1.   

    string swhere=" 0=0 "
    if(!string.IsNullOrEmpty(A))
    {
    swhere+=" AND A='"+a.ToString()+"'";
    }
    sql=sql+swhere;
      

  2.   

    strint sql="  where  1=1 ";
    if(A!=“”)
      {sql += “ and A='+a+'”}
    这样就ok了
      

  3.   

    try
      {
      sql=@"select A from ABC where B  like ‘%XX%’";
      select B from ABC where  .....
      select C from ABC where ....
      }
    要是这样呢?  在加查询条件呢?
      

  4.   

    sql=@"select A from ABC where 1=1 AND B like ‘%"+A+"%’";
    拼接字符串。。不都一样!~...
      

  5.   

    这样不对吧! 我有3个查询语句   每个语句都有不一样的查询条件   如果我直接在后面追加 sql+=   那不就是最后一个select 的查询条件么!
      

  6.   

    哪个用到就在哪个上面加呗。。3个语句一起执行 还是用union all连接成一个表?
      

  7.   

    3个语句都执行 但是在执行的时候  每个都有条件  调用的时候 ds.tables[1] 哪个条件就调那个 现在要在进来的时候在加个条件   
      

  8.   

    if(string.IsNullOrEmpty(sql))
    {
       sql += “and A='+a+'”
    }