Advertisement
abc321123

Untitled

Jan 10th, 2019
128
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 LoginButton_Click(object sender, RoutedEventArgs e)
  2.         {
  3.  
  4.             string connectionString = "Server=localhost;Database=edtest;Uid=root;Password=; ";
  5.  
  6.             using (MySqlConnection db_connect = new MySqlConnection(connectionString))
  7.             {
  8.                 try
  9.                 {
  10.                     db_connect.Open();
  11.  
  12.  
  13.                     MySqlCommand command = db_connect.CreateCommand();
  14.                     command.CommandType = CommandType.Text;
  15.                     command.CommandText = "select * from accounts where username='" + UsernameTextbox.Text + "' and userpass='" + PasswordBox.Password + "'";
  16.                     command.ExecuteNonQuery();
  17.                     DataTable dt = new DataTable();
  18.                     MySqlDataAdapter da = new MySqlDataAdapter(command);
  19.                     da.Fill(dt);
  20.                     int i = Convert.ToInt32(dt.Rows.Count.ToString());
  21.  
  22.                     if (i == 0)
  23.                     {
  24.                         MessageBox.Show("Faild to login, please try again");
  25.                     }
  26.                     else
  27.                     {
  28.                         this.Hide();
  29.                         MainWindowLogged nw = new MainWindowLogged();
  30.                         nw.Show();
  31.                     }
  32.                 }
  33.                 catch (Exception ex)
  34.                 {
  35.  
  36.                     MessageBox.Show(ex.Message);
  37.                 }
  38.             }
  39.  
  40.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement