I am making a simple login form application that is connected with my MySQL
database.
Here is the code that I using for verifying login credentials.
private void login()
{
try
{
MySqlConnection connection = new MySqlConnection("server=sql186.main-hosting.eu; userid=u946814739_SQL; password=testing; database=u946814739_MySQL;");
MySqlDataReader reader;
MySqlCommand cmd = new MySqlCommand("Select * FROM users WHERE username='" + textBox1.Text + "' and password='" + textBox2.Text + "' ", connection);
connection.Open();
reader = cmd.ExecuteReader();
int count = 0;
while (reader.Read())
{
count = count + 1;
}
if (count == 1)
{
//login successful
MessageBox.Show("Login success");
}
else
{
MessageBox.Show("Login failed");
}
connection.Close();
connection.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
It all works great, but now I want to know how to make this method async. So my application doesn't freeze while it's retrieving the data. Any help would be appreciated.
Thanks