public int CheckUser()
        {
            if (this.tbxUserName.Text == "")
            {
                MessageBox.Show("用户名不能为空!", "错误");
            }
            else if (this.tbxPassWord.Text == "")
            {
                MessageBox.Show("密码不能为空!", "错误");
            }
            else
            {
                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;
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (CheckUser() > 0)
            {
                PicManager pic = new PicManager();
                pic.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("用户名不能为空");
            }
        }

解决方案 »

  1.   

    CheckUser()最后一个大括号之前写上一句:return 0;
      

  2.   

            public int CheckUser() 
            { 
                if (this.tbxUserName.Text == "") 
                { 
                    MessageBox.Show("用户名不能为空!", "错误"); 
                } 
                else if (this.tbxPassWord.Text == "") 
                { 
                    MessageBox.Show("密码不能为空!", "错误"); 
                } 
                else 
                { 
                    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; 
                    } 
                }            return 0;  // <---- 最后加上这句!
     
            } 
      

  3.   

     MessageBox.Show("用户名不能为空!", "错误");
    加上 return 0; MessageBox.Show("密码不能为空!", "错误"); 
    加上 return 0;