string sql = "select * from [Text] ";
            if(Uid != "")
            {
                sql = sql + "where Uid= " + Uid + "";
            }
它能放在连接的后面吗?
  public void BindUserlIst(string Uid)是数据库里给的吗?

解决方案 »

  1.   

    没明白什么意思,public void BindUserlIst(string Uid)该函数应该是自己定义的,来绑定用户列表的。不过命名不规范。
      

  2.   

    string sql = "select * from [Text] where 1=1";
    sql += string.IsNullOrEmpty(Uid)?"":" and Uid= " + Uid + "";
      

  3.   


    public void BindUserlIst(string Uid)

         string sql = "select * from [Text] ";
         if(Uid != "")
         {
              sql = sql + "where Uid= " + Uid + "";
         }
         ...
    } 根据输入的查询条件查询数据? 什么是数据库里面给的? 
      

  4.   

    查询语句可以放在使用前的任何位置。只要在Command命令前就可以。和Connection没关系、下面的方法是你自己定义的吧。
      

  5.   

    谢谢大侠们!我还是不懂SQL语句的拼接!谁能在讲的简单点!
      

  6.   

        
    string sql = "select * from [Text]  where 1=1";
        if(Uid != "")
        {
              sql = sql + "and Uid= " + Uid + "";
        } 
        if( num!= "")
        {
              sql = sql + "and num= " + num+ "";
        } 
         sql = sql + " and namelike '%'+@name+'%' ";
        ......
       可以根据查询输入的条件拼接下去... 
       拼接后:select * from [Text]  where 1=1 and Uid=1 and name like %name% and ...