登陆验证
需要一段登陆代码!通过对用户名和密码验证如果正确进入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();