C#验证用户名和密码_c
C#验证用户名和密码由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“c”。
//数据库连接,验证用户名和密码
string testConnectionstring = “Data Source=(local);Initial Catalog=MyQQuser;Integrated Security=pi”;
SqlConnection con = new SqlConnection(testConnectionstring);
string sql = “select Name,Paword,Cname from QQuser”;
SqlCommand com = new SqlCommand(sql, con);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = com;
con.Open();
DataSet ds = new DataSet();
da.Fill(ds, “QQuser”);
DataRow nameRow;
if(comboBox1.Text!= “”)
{
if(textBox1.Text!= “”)
{
for(int i = 0;i
{
nameRow = ds.Tables[“QQuser”].Rows[i];
if(nameRow[0].ToString().Trim()== comboBox1.Text.ToString().Trim()&& nameRow[1].ToString().Trim()== textBox1.Text.ToString().Trim())
{
string sqlaaa = “update QQuser set state='在线' where name='” + comboBox1.Text + “'”;
SqlCommand comaaa = new SqlCommand(sqlaaa, con);
comaaa.ExecuteNonQuery();
//数据修改
Form2 main = new Form2();
main.lb.Text=this.comboBox1.Text.ToString();
main.lbname.Text = nameRow[2].ToString();;
main.Show();
main.Text = “欢迎你:” + nameRow[2].ToString();//把数据库里的数据提取出来
main.name.Text = nameRow[2].ToString();
main.notifyIcon1.Text = nameRow[2].ToString()+ this.comboBox1.Text;con.Close();
main.Show();
this.Hide();
return;
}
}
con.Close();
//MeageBox.Show(“用户名或密码不正确”);
if(MeageBox.Show(“用户名或密码不正确”,“错误
”,MeageBoxButtons.OK,MeageBoxIcon.Error)== DialogResult.OK)
{
textBox1.Text = “”;
}
}
else MeageBox.Show(“请输入密码!”);
}
else MeageBox.Show(“请输入账号和密码!”,“提示
”,MeageBoxButtons.OK,MeageBoxIcon.Asterisk);