My username password is (Location = Hyderabad, Password=Hydd)
private void btnlogin_Click(object sender, EventArgs e)
{
using ( con = new SqlConnection(Helper.ConnectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Select Location, Password FROM UserAccounts WHERE Location=" + "@location AND Password = @password";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@location",cmbLocation.Text.ToString());
cmd.Parameters.AddWithValue("@password",txtPassword.Text.ToString());
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
====> This statement is not executed...
---------------------------------------------------------------------------
if(cmbLocation.Text==null||txtPassword.Text==null)
---------------------------------------------------------------------------
{
MessageBox.Show("Location / Password must not be Empty");
}
===> This statement is created for checking case sensitive, it shows error if the password is "hydd", but other than this if i give any thing like "hyd" it doesn't show any error like password wrong etc.
---------------------------------------------------------------------------
else if (dr["Location"].ToString() == cmbLocation.Text && dr["Password"].ToString()==txtPassword.Text)
---------------------------------------------------------------------------
{
MessageBox.Show("Logged in Successfully");
//this.Hide();
}
else
{
MessageBox.Show("!!! Please Check the Password");
txtPassword.Clear();
cmbLocation.Focus();
}
}
} //con.Dispose() method would be called automatically
}

New Topic/Question
Reply




MultiQuote




|