Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void button2_Click(object sender, EventArgs e)
- {
- int i = 0;
- MySqlCommand comm = con.CreateCommand();
- comm.CommandText = "select * from accountinfo where username = @user and pass = @password";
- comm.Parameters.AddWithValue("@user", textBox1.Text);
- comm.Parameters.AddWithValue("@password", textBox2.Text);
- MySqlDataReader myReader;
- con.Open();
- comm.ExecuteNonQuery();
- myReader = comm.ExecuteReader();
- string accountType = string.Empty;
- DataTable dt = new DataTable();
- MySqlDataAdapter da = new MySqlDataAdapter(comm);
- i = Convert.ToInt32(dt.Rows.Count.ToString());
- while (myReader.Read())
- {
- i = i + 1;
- accountType = myReader["accountType"].ToString();
- }
- if (i == 0)
- {
- MessageBox.Show("Wrong username or password!");
- }
- else if (accountType == "admin")
- {
- MessageBox.Show("Welcome admin");
- this.Hide();
- textBox1.Text = string.Empty;
- textBox2.Text = string.Empty;
- Form3 frm3 = new Form3();
- frm3.Show();
- }
- else
- {
- MessageBox.Show("Welcome");
- this.Hide();
- using(var frm4 = new Form4())
- {
- frm4.FirstName = textBox1.Text;
- frm4.ShowDialog();
- }
- }
- con.Close();
- }
- public partial class Form4 : Form
- {
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string CellNo { get; set; }
- public Form4()
- {
- InitializeComponent();
- }
- private void Form4_Load(object sender, EventArgs e)
- {
- tbUser.Text = FirstName;
- try
- {
- string MyConnection2 = "server=localhost;user id=root;database=account;persistsecurityinfo=True;PASSWORD=test123;SslMode=none";
- string Query = "SELECT firstname = '" + tbFN.Text + "' from accountinfo WHERE username = '" + tbUser + "' " ;
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
- MyAdapter.SelectCommand = MyCommand2;
- DataTable dTable = new DataTable();
- MyAdapter.Fill(dTable);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
Add Comment
Please, Sign In to add comment