帮忙看看下面的代码问题出现在那。
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;
} }
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;
} }
解决方案 »
- C# 十六进制字符串转文件
- 求一种最快的匹配方式
- c#如何调用C++编写的动态连接库(dll)?
- 多线程阻塞无法切换线程
- 用vs2008+c#+winfrom做了个程序,想请教发布的相关问题,先感谢了!
- 关于richtextbox的 lines和text的 问题
- remoting 远程对象需要连接数据库,连接字符串的修改问题
- ~给分~求每10分钟自动从数据库里提取最新数据生成XML方案
- 如何给DataGrid的列标头加中文,这个B/S很容易实现,但是,不知道C/S模式(即windows form) 下如何实现!!!!
- 一个有趣的Icon问题
- C# 如何遍历VS中的语言版本存放在combox控件中(100分相求)
- agsxmpp急,能不能在广域网中使用。
是不是public int CheckUser() 写的有问题呀。
是不是public int CheckUser() 写的有问题呀。
this.tbxUserName.Text.Trim()
this.tbxPassWord.Text.Trim()
试试
cmd.ExecuteNonQuery();
conn.Close();
int n = (int)(sp.Value);
return n; 你断点看看这里面是不是有问题