So I am trying to enclose these 2 queries into try - catch
so if the username/password don't exist then the exception is caught and only an error message window is shown, instead of breaking the whole application:
try
{
command.CommandText = "SELECT username FROM users WHERE username='" + username + "'";
reader = command.ExecuteReader();
reader.Read();
string myUsername = reader.GetString(0);
values[0] = myUsername;
command.CommandText = "SELECT password FROM users WHERE username='" + username + "'";
reader = command.ExecuteReader();
reader.Read();
string myPassword = reader.GetString(0);
values[1] = myPassword;
}
catch (Exception)
{
MessageBox.Show("Wrong username or password!");
}
I know the logic of checking for the correct username and it's particular password is not correct but I am gonna fix that later. I now want just to know how to show the message instead of breaking the whole process.