SqlConnection yy = new SqlConnection();
yy.ConnectionString = "server=.;database=888;uid=sa;pwd=123";
yy.Open();
SqlCommand nn = new SqlCommand();
nn.Connection = yy;
nn.CommandText = "select * from users where name=@name";
nn.Parameters.Add(new SqlParameter("@name", textBox1.Text));
SqlDataReader rr = nn.ExecuteReader();
if (rr.Read())
{
if (rr[2].ToString() == textBox2.Text)
{
Form2 ff = new Form2();
ff.Show();
}
else
{
MessageBox.Show("密码错误,请重新输入!");
textBox2.Text = "";
}
}
else
{
MessageBox.Show("用户名不存在!请重新输入!");
textBox1.Text = "";
textBox2.Text = "";
}这各句都是什么意思啊??
望高手指点~~~~
yy.ConnectionString = "server=.;database=888;uid=sa;pwd=123";
yy.Open();
SqlCommand nn = new SqlCommand();
nn.Connection = yy;
nn.CommandText = "select * from users where name=@name";
nn.Parameters.Add(new SqlParameter("@name", textBox1.Text));
SqlDataReader rr = nn.ExecuteReader();
if (rr.Read())
{
if (rr[2].ToString() == textBox2.Text)
{
Form2 ff = new Form2();
ff.Show();
}
else
{
MessageBox.Show("密码错误,请重新输入!");
textBox2.Text = "";
}
}
else
{
MessageBox.Show("用户名不存在!请重新输入!");
textBox1.Text = "";
textBox2.Text = "";
}这各句都是什么意思啊??
望高手指点~~~~
SqlConnection yy = new SqlConnection(); //数据库连接
yy.ConnectionString = "server=.;database=888;uid=sa;pwd=123"; //设定连接字符串
yy.Open(); //打开连接
SqlCommand nn = new SqlCommand(); //数据库命令,sql
nn.Connection = yy;
nn.CommandText = "select * from users where name=@name"; //sql语句,用于取得name指定的一行
nn.Parameters.Add(new SqlParameter("@name", textBox1.Text)); //设定name条件为textBox1得值
SqlDataReader rr = nn.ExecuteReader(); //执行sql语句
if (rr.Read()) //读取纪录
{
if (rr[2].ToString() == textBox2.Text) //如果密码正确
{
Form2 ff = new Form2();
ff.Show();
}
else //密码错误
{
MessageBox.Show("密码错误,请重新输入!");
textBox2.Text = "";
}
}
else //没有记录,用户名不存在
{
MessageBox.Show("用户名不存在!请重新输入!");
textBox1.Text = "";
textBox2.Text = "";
}