if (textBox_user.Text == "")
            {
               MessageBox.Show("用户名为空!");
               textBox_user.Focus();
                return;
            }
            if (textBox_pwd.Text == "")
            {
                MessageBox.Show("密码不能为空!");
                textBox_pwd.Focus();
                return;
            }
            SqlConnection cmd12 = new SqlConnection("server=127.0.0.1;uid=sa;pwd=123;database=REMIS");
            string str12 = "select uid,pwd from user where uid='" +textBox_user.Text+"'and pwd='" +textBox_pwd.Text+"'";
            cmd12.Open();
            SqlCommand com = new SqlCommand(str12,cmd12); ;
            SqlDataReader dr = com.ExecuteReader();
            if (dr.Read())
            {
                this.Close();
                new ALL().Show();
                
            }
            else
            {
                MessageBox.Show("登录错误,请重新输入!");
                textBox_user.Clear();
                textBox_pwd.Clear();
                cmd12.Close();
            }

解决方案 »

  1.   

    string str12 = "select count(*) from user where uid='" +textBox_user.Text+"'and pwd='" +textBox_pwd.Text+"'";
                cmd12.Open();
                SqlCommand com = new SqlCommand(str12,cmd12); ;
                int sum=Convert.ToInt32(com.ExecuteScalar());
                if (sum>0)
                {
                    //成功
                    new ALL().Show();
                   
                }
                else
                {
                    MessageBox.Show("登录错误,请重新输入!");
                    textBox_user.Clear();
                    textBox_pwd.Clear();
                    cmd12.Close();
                }
    楼主对象实例命名有点问题,取的名字不好理解
      

  2.   


                dr.Read()
                if (dr.HasRows)  这个改下试试 
                { 
                    this.Close(); 
                    new ALL().Show(); 
                    
                } 
                else 
                { 
                    MessageBox.Show("登录错误,请重新输入!"); 
                    textBox_user.Clear(); 
                    textBox_pwd.Clear(); 
                    cmd12.Close(); 
                }
      

  3.   

    string str12 = "select count(*) from user where uid='" +textBox_user.Text+"'and pwd='" +textBox_pwd.Text+"'"; 
                cmd12.Open(); 
                SqlCommand com = new SqlCommand(str12,cmd12); ; 
                SqlDataReader dr = new SqlDataReader(com); 
                // 数据的取得
                  DataSet ds = new DataSet();
                dr.Fill(ds);
                DateTable dtlResult = ds.Tables[0];
                if (dtSearch.Rows.Count > 0) 
                { 
                    //成功 
                    new ALL().Show(); 
                  
                } 
                else 
                { 
                    MessageBox.Show("登录错误,请重新输入!"); 
                    textBox_user.Clear(); 
                    textBox_pwd.Clear(); 
                } 
                cmd12.Close();