string sqlstr="select userid,pass from auth where userid="+userid.Text.Trim()+" and pass="+pass.Text.Trim()+"";
------------->
string sqlstr="select userid,pass from auth where userid='"+userid.Text.Trim()+"' and pass='"+pass.Text.Trim()+"'";单引号不要忘了!!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    你已经使用了sqlConnection控件,为什么还需要实例化一个SqlConnection呢?
      

  2.   

    sqlconnection1我已经删除了,自己写
      

  3.   

    shuker(我是一只小花猪) 
    我加了'还是不行啊
    同样的问题
      

  4.   

    和我上次一样。
    试试:
    DataSet my=new DataSet();
    this.mydata.Fill(my,"Table");//在这里中断或者: DataSet my=new DataSet("auth")
           this.mydata.Fill(my,"auth")还不行检查下连接字符串。
      

  5.   

    还是不行,连接字符串没有问题,是不是如果没有select到数据也会报主要的错误
      

  6.   

    如果my=null是不是也会报这样的错误
      

  7.   

    this.mydata.Fill(my)有没有错呢?
      

  8.   

    SqlCommand myCommand=new SqlCommand();
    myCommand.CommandText=sqlstr;
    myCommand.Connection=myconn;
    SqlDataAdapter mydata=new SqlDataAdapter(myCommand);
    这样试一下
      

  9.   

    SUNTYQ(雨人) 
    还是不行
      

  10.   

    private void button1_Click(object sender, System.EventArgs e)
    {
    string cnnstr=@"Data Source=(Local);Integrated Security=SSPI;Initial Catalog=testfair2";
    SqlConnection myconn=new SqlConnection(cnnstr);
    myconn.Open();
    //MessageBox.Show(this.sqlConnection1.ConnectionString.ToString());
    string sqlstr="select userid,pass from auth where userid='"+userid.Text.Trim()+" 'and pass='"+pass.Text.Trim()+"'";
    DataSet my=new DataSet("auth");
    SqlDataAdapter mydata=new SqlDataAdapter(sqlstr,myconn);
    mydata.Fill(my,"auth");//在
    dataGrid1.SetDataBinding(my,"auth");
                dataGrid1.Refresh();
    }测试你的代码。改动后,成功。
      

  11.   

    BeginnerBBB() 
    是不是加内存可以该改善这样的情况
      

  12.   

    与内存没有什么关系,一个库的连接数是在库中设置的。每次连接的时候会占用一个连接,如果不释放,它会一直占用,一直等到.net来回收它。如果连接都被占用了,当你再连接库的时候就会失败。
      

  13.   

    BeginnerBBB() 
    哦这样啊,谢谢
      

  14.   

    并不是BeginnerBBB()说的占用了数据库连接
    DataSet采用断线连接
    this.mydata.Dispose()也会自动施放资源;
      

  15.   

    to WalkingLife() 
    this.mydata.Fill(my,"auth");//在这里中断
    this.mydata.Dispose();this.mydata.Dispose()也会自动施放资源;可是这是最后一句啊,释放应该没问题的。在前一句被中断的