I am new to c# and visual studios and i am creating a windows form application that requires a username and password to log in. I have successfully implemented the database to register a user but cannot seem to get the login to work. There is two errors in the code below:
private void btnLogin_Click(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection();
con.ConnectionString = "datasource=127.0.0.1;port=3306;username=root;password=;";
Int32 verify;
string query1 = "Select count(*) from Login where Username='" + Username.Text + "' and Password='" + Password.Text + "' ";
MySqlCommand cmd1 = new MySqlCommand(query1, con);
con.Open();
verify = Convert.ToInt32(cmd1.ExecuteScalar());
con.Close();
if (verify > 0)
{
new FormMainMenu().Show();
this.Hide();
}
else
{
MessageBox.Show("Username or Password is Incorrect")
}
}
The Username.Text
and the Password.Text
are both underlined and says the name
does not exist in the current context.
If anyone has any solutions to this, I would be very grateful. Thanks