Witam.
Mam mały problem.
if (txtUser.Text == "" && txtPassword.Text == "")
{
MessageBox.Show("Error: Fields Cannot Be Empty!", "eHacks Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (txtUser.Text.Length < 3 && txtPassword.Text.Length < 3)
{
MessageBox.Show("Error: Text In Fields Must Be Longer Than 3 Chars!", "eHacks Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
OleDbConnection con;
con = new OleDbConnection(conStr);
OleDbCommand cmd = new OleDbCommand("SELECT Username, Password FROM Users WHERE Username="+txtUser.Text+" AND Password="+txtPassword.Text, con); // WHERE Username=" + txtUser.Text + " AND Password=" + txtPassword.Text
cmd.Parameters.Add(new OleDbParameter("@Username", txtUser.Text));
cmd.Parameters.Add(new OleDbParameter("@Password", txtPassword.Text));
con.Open();
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
if (reader.GetString(0) == txtUser.Text && reader.GetString(1) == txtPassword.Text) //GetString(0) is Username GetString(1) is Password
{
MessageBox.Show("Holy Sh*t! It works! :D");
break;
}
else
{
MessageBox.Show("There is no such an User or Password is invalid!");
break;
}
}
con.Close();
}
Chcę aby, jezeli użytkownik nie istnieje w bazie pokazywało to, a nie po prostu kończyło połączenie.