Example #1
0
        public void login_Click(object sender, EventArgs e)
        {
            string          Accessfilename = @"\\注册用户表.mdb";
            string          Constr         = "Provider=Microsoft.ace.OLEDB.12.0;Data Source=" + Application.StartupPath + Accessfilename;
            OleDbConnection con            = new OleDbConnection(Constr);

            con.Open();
            string          selectsql1 = "Select * from UsersDat where Users='" + textBox1.Text.ToString() + "'";
            string          selectsql2 = "Select * from PasswordDat where password='******'";
            OleDbCommand    odc1       = new OleDbCommand(selectsql1, con);
            OleDbCommand    odc2       = new OleDbCommand(selectsql2, con);
            OleDbDataReader odr1;
            OleDbDataReader odr2;

            odr1 = odc1.ExecuteReader();
            odr2 = odc2.ExecuteReader();
            if (odr1.Read() && odr2.Read())
            {
                PaintForm paintForm = new PaintForm();
                paintForm.Owner = this;
                paintForm.Show();
            }
            else
            {
                MessageBox.Show("用户名或密码错误!");
                return;
            }
            con.Close();

            if (textBox1.Text.Trim() == "")
            {
                MessageBox.Show("用户名不能为空!");
            }
            if (textBox2.Text.Trim() == "")
            {
                MessageBox.Show("密码不能为空!");
            }
        }