SqlCeConnection sqlCnn = new SqlCeConnection("Data Source=" + Application.StartupPath + "\\mainDB.sdf");
SqlCeCommand sqlCmd = new SqlCeCommand("SELECT * FROM Accounts WHERE (username = @user AND password = @pass)", sqlCnn);
sqlCmd.Parameters.Add("@user", textBox1.Text);
sqlCmd.Parameters.Add("@pass", textBox2.Text);
sqlCnn.Open();
SqlCeDataReader reader = sqlCmd.ExecuteReader();
while (reader.Read())
{
// Some code ...
}
I have this code that reads some values from a database but I want to check if any value is returned from the database. I want to check if the username
and password
from the database is equal to textBox1
and textBox2
and if not, return a failure message.