我数据库中有一表,我输入两个值和表中第二列第三列的值比较,实现简单的密码验证,可每次都显示“用户名或密码错误”
代码如下,该怎么解决?
SqlConnection con = new SqlConnection("server=.;database=superet;Trusted_Connection=True");
SqlCommand cmd = new SqlCommand();
con.Open();
cmd.Connection = con;
string str = "select * from ad;";
SqlDataAdapter ada = new SqlDataAdapter(str, con);
DataTable dt = new DataTable();
dt=new DataTable();
ada.Fill(dt);
int i,j=0;
for (i = 0; i < dt.Rows.Count; i++)
{
if ((textBox1.Text.ToString() == (dt.Rows[i][1].ToString())) && (textBox2.Text.ToString() == (dt.Rows[i][2].ToString())))
{
MessageBox.Show("成功");
j = 1;
}
}
if(j==0)
{
MessageBox.Show("用户名或密码错误");
}
代码如下,该怎么解决?
SqlConnection con = new SqlConnection("server=.;database=superet;Trusted_Connection=True");
SqlCommand cmd = new SqlCommand();
con.Open();
cmd.Connection = con;
string str = "select * from ad;";
SqlDataAdapter ada = new SqlDataAdapter(str, con);
DataTable dt = new DataTable();
dt=new DataTable();
ada.Fill(dt);
int i,j=0;
for (i = 0; i < dt.Rows.Count; i++)
{
if ((textBox1.Text.ToString() == (dt.Rows[i][1].ToString())) && (textBox2.Text.ToString() == (dt.Rows[i][2].ToString())))
{
MessageBox.Show("成功");
j = 1;
}
}
if(j==0)
{
MessageBox.Show("用户名或密码错误");
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货