private bool CompareStrings(string string1, string string2)
{
return String.Compare(string1, string2, true, System.Globalization.CultureInfo.InvariantCulture) == 0 ? true : false;
}
private void btnlogin_Click_1(object sender, EventArgs e)
{
if (txtusername.Text == "" || txtpassword.Text == "")
{
MessageBox.Show("Please Fill All The Details", "Zain -Ul- Arifeen");
txtusername.Focus();
}
else
{
cnn.ConnectionString = "Data Source=zain\\SqlExpress;Initial Catalog=Studentinformationsystem;Integrated Security=true";
cnn.Open();
SqlCommand cmd = new SqlCommand("SELECT username,password FROM login WHERE username='" + txtusername.Text + "' and password='" + txtpassword.Text + "'", cnn);
SqlDataReader dr = cmd.ExecuteReader();
string userText = txtusername.Text;
string passText = txtpassword.Text;
while (dr.Read())
{
if
(this.CompareStrings(dr["username"].ToString(), txtusername.Text) &&
this.CompareStrings(dr["password"].ToString(), txtpassword .Text ))
{
frm.Show();
this.Hide();
}
else
{
MessageBox.Show("Invalid User or wrong Password", "Zain -Ul- Arifeen");
}
}
dr.Close();
cnn.Close();
|