Guest User

Untitled

a guest
May 17th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. int i = 0;
  4. MySqlCommand comm = con.CreateCommand();
  5. comm.CommandText = "select * from accountinfo where username = @user and pass = @password";
  6. comm.Parameters.AddWithValue("@user", textBox1.Text);
  7. comm.Parameters.AddWithValue("@password", textBox2.Text);
  8. MySqlDataReader myReader;
  9. con.Open();
  10. comm.ExecuteNonQuery();
  11. myReader = comm.ExecuteReader();
  12. string accountType = string.Empty;
  13. DataTable dt = new DataTable();
  14. MySqlDataAdapter da = new MySqlDataAdapter(comm);
  15. i = Convert.ToInt32(dt.Rows.Count.ToString());
  16.  
  17. while (myReader.Read())
  18. {
  19. i = i + 1;
  20. accountType = myReader["accountType"].ToString();
  21. }
  22. if (i == 0)
  23. {
  24. MessageBox.Show("Wrong username or password!");
  25. }
  26. else if (accountType == "admin")
  27. {
  28. MessageBox.Show("Welcome admin");
  29. this.Hide();
  30. textBox1.Text = string.Empty;
  31. textBox2.Text = string.Empty;
  32. Form3 frm3 = new Form3();
  33. frm3.Show();
  34. }
  35. else
  36. {
  37. MessageBox.Show("Welcome");
  38. this.Hide();
  39. using(var frm4 = new Form4())
  40. {
  41.  
  42. frm4.FirstName = textBox1.Text;
  43. frm4.ShowDialog();
  44. }
  45. }
  46. con.Close();
  47. }
  48.  
  49. public partial class Form4 : Form
  50. {
  51. public string FirstName { get; set; }
  52. public string LastName { get; set; }
  53. public string CellNo { get; set; }
  54.  
  55. public Form4()
  56. {
  57. InitializeComponent();
  58. }
  59.  
  60. private void Form4_Load(object sender, EventArgs e)
  61. {
  62. tbUser.Text = FirstName;
  63. try
  64. {
  65. string MyConnection2 = "server=localhost;user id=root;database=account;persistsecurityinfo=True;PASSWORD=test123;SslMode=none";
  66. string Query = "SELECT firstname = '" + tbFN.Text + "' from accountinfo WHERE username = '" + tbUser + "' " ;
  67. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
  68. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
  69. MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
  70. MyAdapter.SelectCommand = MyCommand2;
  71. DataTable dTable = new DataTable();
  72. MyAdapter.Fill(dTable);
  73. }
  74. catch (Exception ex)
  75. {
  76. MessageBox.Show(ex.Message);
  77. }
  78.  
  79. }
  80. }
Add Comment
Please, Sign In to add comment