110,538
社区成员
发帖
与我相关
我的任务
分享
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; // <---- 最后加上这句!
}