使用Access 2013数据库的Visual Studio 2017中的登录表单

时间:2019-01-02 05:58:20

标签: visual-studio ms-access

private void SignIn_Click(object sender, EventArgs e)
    {
        try
        {
            string constring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\project SMS\School management\School Management System\DB\Schoolmanagmentsystem.accdb";

            string cmdText= "select count(*) from User Where UserName= ?and [Password]=?" ;
            using (OleDbConnection con = new OleDbConnection(constring))
            using (OleDbCommand cmd = new OleDbCommand(cmdText, con))
            {
                con.Open();
                cmd.Parameters.AddWithValue("@p1", UesrNameTextBox.Text);
                cmd.Parameters.AddWithValue("@p2", passwordTextBox.Text);  // <- is this a variable or a textbox?
                int result = (int)cmd.ExecuteScalar();
                if (result > 0)
                    MessageBox.Show("Login Successful");
                else
                    MessageBox.Show("Invalid Credentials, Please Re-Enter");
                con.Close();
            }
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }

0 个答案:

没有答案