private void button3_Click(object sender, EventArgs e) { var con = new MySqlConnection("server=localhost;user id=root;database=kys"); MySqlCommand cmd; MySqlDataReader mdr; con.Open(); var selectQuery = "select * " + "from scholarship_confirm" + " where id = " + label3.Text + " and password = '******'"; cmd = new MySqlCommand(selectQuery, con); mdr = cmd.ExecuteReader(); if (mdr.Read()) { con.Close(); con.Open(); selectQuery = "update scholarship" + " set status = '" + label4.Text.Trim() + " Grabbed!' where id = " + label3.Text.Trim(); cmd = new MySqlCommand(selectQuery, con); mdr = cmd.ExecuteReader(); while (mdr.Read()) { } con.Close(); MessageBox.Show(@"Congratulations! You have successfully grabbed this scholarship!", @"Congratulations!", MessageBoxButtons.OK); Hide(); var f = new DashboardStudent(); f.Show(); } else { con.Close(); MessageBox.Show(@"Incorrect passcode!", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void button1_Click(object sender, EventArgs e) { var r = new Regex(@"\D"); if (r.IsMatch(textBox1.Text.Trim())) { MessageBox.Show(@"ID must be a number. Can not contain alphabet, white space or any special character.", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (textBox1.Text.Trim().Length != 9) { MessageBox.Show(@"ID can have 9 digits only", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (textBox2.Text.Trim() == "") { MessageBox.Show(@"Password can not be empty.", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var con = new MySqlConnection("server=localhost;user id=root;database=kys"); MySqlCommand cmd; MySqlDataReader mdr; con.Open(); var selectQuery = "select *" + " from login_student where id = '" + textBox1.Text.Trim() + "' and password = '******'"; cmd = new MySqlCommand(selectQuery, con); mdr = cmd.ExecuteReader(); if (mdr.Read()) { con.Close(); con.Open(); selectQuery = "select *" + " from student where id = '" + textBox1.Text.Trim() + "'"; cmd = new MySqlCommand(selectQuery, con); mdr = cmd.ExecuteReader(); mdr.Read(); Username = mdr[1].ToString(); Hide(); var f = new DashboardStudent(); f.Show(); } else { MessageBox.Show(@"Incorrect username or password!", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } con.Close(); }