I have a trouble in my login form.
The program doesnt execute my else statement, especially if I'm going input wrong usernames and passwords.
It just did nothing. NO error warnings, etc...
please help.. :(
private bool CompareStrings(string string1, string string2)
{
return String.Compare(string1, string2, true, System.Globalization.CultureInfo.InvariantCulture) == 0 ? true : false;
}
private void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection Connect = new SqlConnection();
Connect.ConnectionString = @"Data Source=blah;"
+ @"Initial Catalog= ITFixedAsset;" + "Integrated Security=true";
Connect.Open();
SqlCommand cmd = new SqlCommand("SELECT ISNULL(username, '') AS username, ISNULL(password, '') AS password FROM dim_user_accounts WHERE username='" + txtbxUserName.Text + "' and password='" + txtbxPassword.Text + "'", Connect);
SqlDataReader dr = cmd.ExecuteReader();
string userText = txtbxUserName.Text;
string passText = txtbxPassword.Text;
dr.Read();
if (CompareStrings(dr["username"].ToString(), userText) && CompareStrings(dr["password"].ToString(), passText))
{
MessageBox.Show("Log-in Successful.");
formMain main = new formMain();
this.Hide();
main.Show();
}
else
MessageBox.Show("Log-in Failed.");