rwahdan2023
Member
- Joined
- Aug 28, 2023
- Messages
- 10
- Programming Experience
- 1-3
Hi,
I am trying to run this code but getting error.
code:
the error:
I am always getting success even if the user or password is incorrect
I am trying to run this code but getting error.
code:
C#:
try
{
SqlConnection conn =
new SqlConnection("Data Source = .; " +
"Initial Catalog = users; Persist Security Info = True; " +
"User ID = sa; Password = ***********");
SqlCommand cmd = new SqlCommand("select * from users");
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@username", txtuser.Text);
cmd.Parameters.AddWithValue("@password", txtpass.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Success!");
}
else
{
MessageBox.Show("Not Success!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
I am always getting success even if the user or password is incorrect
Last edited: