验证登陆代码
求验证登陆代码一段。用户通过用户名及密码来访问登陆。如果用户名、密码匹配成功怎显示from2,否则弹出提示信息
程序代码:
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "/" + "DB.mdb"); aConnection.Open();///打开数据库 String SQLString = "select * from user where name='" + textBox1.Text + "' and password='" + textBox2.Text + "' ";///设置sql 查询语句 OleDbDataAdapter myadapter = new OleDbDataAdapter(SQLString, aConnection); ///创建适配器,执行sql 查询 DataSet ds = new DataSet(); ///建立数据集 myadapter.Fill(ds); ///将查询结果加入 ds 中 if (ds.Tables[0].Rows.Count > 0) { OleDbDataAdapter qx_adapter = new OleDbDataAdapter("select qx from user where name='" + textBox1.Text.Trim() + "'", aConnection); DataSet ds_qx = new DataSet(); qx_adapter.Fill(ds_qx); qx = Convert.ToInt32(ds_qx.Tables[0].Rows[0]["qx"]); /// textBox4.Text = Convert.ToString(qx); form2_01.Show(); form2_01.cdxs(qx); } else { MessageBox.Show("你按了确定"); MessageBox.Show("对不起,请输入正确的用户名和密码"); } aConnection.Close();///关闭数据库连接(必须) this.Hide();。