帮忙看看下面的代码问题出现在那。
private void btnLogin_Click(object sender, EventArgs e)
        {
           
            
            if (CheckUser() > 0)
            {
                PicManager pic = new PicManager();
                pic.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("用户名或密码不正确");
            }        }
 public int CheckUser()
        {
            if (this.tbxUserName.Text == "")
            {
                MessageBox.Show("用户名不能为空!", "错误");
            }
            else if (this.tbxPassWord.Text == "")
            {
                MessageBox.Show("密码不能为空!", "错误");
            }            string str = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
            SqlConnection conn = new SqlConnection(str);
            SqlCommand cmd = new SqlCommand("Login", conn);            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter UserName = new SqlParameter("@username", SqlDbType.VarChar, 50);
            UserName.Value = this.tbxUserName.Text;
            cmd.Parameters.Add(UserName);            SqlParameter PassWord = new SqlParameter("@pwd", SqlDbType.VarChar, 50);
            UserName.Value = this.tbxPassWord.Text;
            cmd.Parameters.Add(PassWord);            SqlParameter sp = new SqlParameter("@return", SqlDbType.Int, 4);            sp.Direction = ParameterDirection.Output;
            cmd.Parameters.Add(sp);            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                int n = (int)(sp.Value);
                return n;
            }
            catch
            {
                return 0;
            }        }

解决方案 »

  1.   

    数据库连接,什么的没有问题,但是,不管比输入的密码和用户名是什么,他都提示是错误的。
    是不是public int CheckUser() 写的有问题呀。
      

  2.   

    数据库连接,什么的没有问题,但是,不管比输入的密码和用户名是什么,他都提示是错误的。
    是不是public int CheckUser() 写的有问题呀。
      

  3.   

    提示什么错误?
    this.tbxUserName.Text.Trim()
    this.tbxPassWord.Text.Trim()
    试试
      

  4.   

                    conn.Open(); 
                    cmd.ExecuteNonQuery(); 
                    conn.Close(); 
                    int n = (int)(sp.Value); 
                    return n; 你断点看看这里面是不是有问题