Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void button1_Click(object sender, System.EventArgs e)
- {
- string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=user.mdb;User Id=admin;Password=temppass";
- // create an open the connection
- OleDbConnection conn = new OleDbConnection(conString);
- conn.Open();
- // create the DataSet
- DataSet ds = new DataSet();
- // create the adapter and fill the DataSet
- OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from users", conn);
- adapter.Fill(ds);
- // close the connection
- conn.Close();
- DataTable dt = ds.Tables[0];
- foreach (DataRow dr in dt.Rows)
- {
- string DBuservalue = null;
- string DBpassvalue = null;
- string InputUser = null;
- string InputPass = null;
- DBuservalue = dr["username"].ToString();
- DBpassvalue = dr["password"].ToString();
- InputUser = this.Username.Text.ToString();
- InputPass = this.Password.Text.ToString();
- if(DBuservalue == InputUser && DBuservalue != "" && DBpassvalue != "")
- if(DBpassvalue == InputPass)
- {
- Form2 UserForm = new Form2();
- UserForm.Show();
- this.Hide();
- login = true;
- break;
- }
- DBuservalue = null;
- DBpassvalue = null;
- }
- if(login == false)
- MessageBox.Show("No such user or password!","Login failed",MessageBoxButtons.OK,MessageBoxIcon.Information);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement