Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. private void button1_Click(object sender, System.EventArgs e)
  2.         {
  3.            
  4.             string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=user.mdb;User Id=admin;Password=temppass";                
  5.             // create an open the connection          
  6.             OleDbConnection conn = new OleDbConnection(conString);
  7.             conn.Open();
  8.                        
  9.  
  10.             // create the DataSet
  11.             DataSet ds = new DataSet();
  12.  
  13.             // create the adapter and fill the DataSet
  14.             OleDbDataAdapter adapter =  new OleDbDataAdapter("Select * from users", conn);
  15.             adapter.Fill(ds);
  16.  
  17.             // close the connection
  18.             conn.Close();
  19.  
  20.             DataTable dt = ds.Tables[0];
  21.             foreach (DataRow dr in dt.Rows)
  22.             {
  23.                 string DBuservalue = null;
  24.                 string DBpassvalue = null;
  25.                 string InputUser = null;
  26.                 string InputPass = null;
  27.  
  28.                 DBuservalue = dr["username"].ToString();
  29.                 DBpassvalue = dr["password"].ToString();
  30.                
  31.                 InputUser = this.Username.Text.ToString();
  32.                 InputPass = this.Password.Text.ToString();
  33.  
  34.                 if(DBuservalue == InputUser && DBuservalue != "" && DBpassvalue != "")
  35.                     if(DBpassvalue == InputPass)
  36.                     {
  37.                        
  38.                         Form2 UserForm = new Form2();
  39.                         UserForm.Show();
  40.                         this.Hide();
  41.                         login = true;
  42.                         break;
  43.                     }
  44.                 DBuservalue = null;
  45.                 DBpassvalue = null;
  46.                
  47.             }
  48.            
  49.             if(login == false)
  50.                 MessageBox.Show("No such user or password!","Login failed",MessageBoxButtons.OK,MessageBoxIcon.Information);
  51.                      
  52.  
  53.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement