简单易懂方便coppy
SqlCommand com = new SqlCommand(cmd, conConnection); SqlDataReader reader = com.ExecuteReader();
while (reader.Read())//从数据库读取用户信息
{
User = reader["用户名"].ToString();
Pwd = reader["密码"].ToString();
if (User.Trim () == textBox1.Text & Pwd.Trim () == textBox2.Text) {
flagshow = true; //用户名存在于数据库,则为true
}
}
reader.Close();
conConnection.Close();
if (flagshow == true)
{
showMainForm();//用户存在,返回登录界面
}
else
{
MessageBox.Show("用户不存在或密码错误!", "提示");
return;
}
}
private void showMainForm()//登录成功,显示主界面
{
this.Close();
Form1 f1 = new Form1();
http://www.77cn.com.cnbel1.Visible = false;
http://www.77cn.com.cnbel3.Visible = false;
f1.linkLabel1.Visible = false;
f1.linkLabel2.Visible = false;
http://www.77cn.com.cnbel2.Visible = true;
http://www.77cn.com.cnbel2.Text = "欢迎你," + textBox1 .Text ;
f1.Show();
}