本文介绍了如何在Windows窗体应用程序中验证用户名密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞!private void button1_Click_1(object sender, EventArgs e){ SqlConnection con = new SqlConnection(@"data source=ABHINAV-PC\ABHI;integrated security=true;initial catalog=ATM;"); con.Open(); DataSet ds = new DataSet(); if (textBox1.Text == "@UserName" && textBox2.Text == "@Password") { Administrator_Home ah = new Administrator_Home(); ah.Show(); } else MessageBox.Show("invalid username or password");}推荐答案 private void btnOk_Click(object sender, EventArgs e) { SqlConnection connect = new SqlConnection(@"data source=ABHINAV-PC\ABHI;integrated security=true;initial catalog=ATM;");DataTable dt1 = new DataTable();string strcmd1 = "";SqlDataAdapter cmd1 = new SqlbDataAdapter; connect.Open(); strcmd1 = ("SELECT UserName, PassWord FROM Admin WHERE UserName='" & Textbox1.Text.Trim() & "' and Password='" & Textbox1.Text.Trim() & "'");cmd1 = new SqlDataAdapter(new SqlCommand(strcmd1));cmd1.SelectCommand.Connection = connect;cmd1.Fill(dt1)if ((dt1.Rows.Count > 0)) { Administrator_Home ah = new Administrator_Home(); ah.Show();} else {MessageBox.Show("invalid username or password");} } }} 这篇关于如何在Windows窗体应用程序中验证用户名密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 19:06