string name = textBox1.Text;
string pwd = textBox2.Text;
string sqlStr = @"Data Source=lenovo-e0bed844;Initial Catalog=book;Uid=qq;Pwd=123";
using (SqlConnection conn = new SqlConnection(sqlStr))
{
string sql = "select Upwd from [user1] where Uname=@name";
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(new SqlParameter("@name", name));
conn.Open();
using (SqlDataReader sr = cmd.ExecuteReader())
{
if (sr.Read())
{
string pwd1 = sr["Upwd"].ToString();
//MessageBox.Show(pwd1);
if (pwd == pwd1)
{
MessageBox.Show("登录成功");
}
else
{ MessageBox.Show("密码错误");
}
}
else
{
MessageBox.Show("用户名不存在");
}
}
}
}
刚才问题找到了,现在又有了新问题
就是我的密码对了还是提示错误
什么原因 还有 请解释一下SqlDataReader.Read() 的作用
string pwd = textBox2.Text;
string sqlStr = @"Data Source=lenovo-e0bed844;Initial Catalog=book;Uid=qq;Pwd=123";
using (SqlConnection conn = new SqlConnection(sqlStr))
{
string sql = "select Upwd from [user1] where Uname=@name";
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(new SqlParameter("@name", name));
conn.Open();
using (SqlDataReader sr = cmd.ExecuteReader())
{
if (sr.Read())
{
string pwd1 = sr["Upwd"].ToString();
//MessageBox.Show(pwd1);
if (pwd == pwd1)
{
MessageBox.Show("登录成功");
}
else
{ MessageBox.Show("密码错误");
}
}
else
{
MessageBox.Show("用户名不存在");
}
}
}
}
刚才问题找到了,现在又有了新问题
就是我的密码对了还是提示错误
什么原因 还有 请解释一下SqlDataReader.Read() 的作用
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货