I have an login which works, but i only can login with the first user in the table
Can anyone explain why?
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
SqlConnection sqlCon = new SqlConnection(@"Data Source=user\SQLEXPRESS; User ID=user;password=password;Initial Catalog=login;Trusted_Connection=True;");
try
{
if (sqlCon.State == System.Data.ConnectionState.Closed)
sqlCon.Open();
string query = "SELECT * FROM tblUser WHERE Username=@Username AND Password=@Password";
SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
sqlCmd.CommandType = System.Data.CommandType.Text;
sqlCmd.Parameters.AddWithValue("@Username", txtUsername.Text);
sqlCmd.Parameters.AddWithValue("@Password", pwd.Password);
int count = Convert.ToInt32(sqlCmd.ExecuteScalar());
if (count == 1)
{
MainDashboard window = new MainDashboard();
this.Close();
window.ShowDialog();
}
else
{
MessageBox.Show("Wrong Username or Password");
}
}
catch (Exception)
{
throw;
}
}
my table name is tblUsers and i have 2 users but i can only succesfully login with the first user in my table