大半天了,我实在找不出究竟错在哪~正大汗-_-U
验证管理员输入的帐号和密码是否正确
在“登录”按钮我写了如下的代码:
private void btnlogin_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(txtuser.Text) || String.IsNullOrEmpty(txtpwd.Text))
{ MessageBox.Show("输入帐号/密码再登录", "错误提示"); return; }
int i, flag = 0;
label1.Text = null;//密码下面有个lable1,用来显示帐号和密码。
string str1 = txtuser.Text; string str2 = txtpwd.Text;
string StrSel = "select * from [db_user]";
string strRow1 = ""; string strRow2 = "";
string ConnectStr = "server=localhost;database=ClassDesign;uid=sa;pwd=;";
SqlConnection MyCon = new SqlConnection(ConnectStr);
try
{
MyCon.Open();
this.Text = "已连接,正在登录";
}
catch (SqlException e1)
{
MessageBox.Show("连接失败", "出错");
return;
}
SqlCommand MyCmd = new SqlCommand(StrSel,MyCon);
SqlDataAdapter MydataAdapter = new SqlDataAdapter();
MydataAdapter.SelectCommand = MyCmd;
DataSet MyDs = new DataSet();
MydataAdapter.Fill(MyDs,"db_user");
for (i = 0; i < MyDs.Tables["db_user"].Rows.Count; i++)
{
strRow1 = MyDs.Tables["db_user"].Rows[i]["user"].ToString();
label1.Text += strRow1;
strRow2 = MyDs.Tables["db_user"].Rows[i]["pwd"].ToString();
label1.Text += strRow2;
if (str1 == strRow1 && str2 == strRow2)
{ flag = 1; break; }
}
if (flag == 1)
{
this.Hide();
FrmMain f = (FrmMain)this.ParentForm;
f.updataMenu();
}
else
{
MessageBox.Show("帐号/密码错误","错误提示");
txtuser.Focus();
}
}
明明我输入正确,但就是不肯让我登录,气死了
实在是看不出代码错在哪里