Arslan Ali

Arslan Ali

  • NA
  • 106
  • 3.3k

Login Form , Facing A Problem

Mar 20 2018 9:49 PM
Hi , I Am Creating A LOGIN FORM For My new Project , But The Query Seems To Generate The Error , Please Check
 
con.Open();
string txtUser = txtUserName.Text;
string txtPwd = txtPassword.Text;
//SqlCommand getuserinfo = new SqlCommand("SELECT * FROM tbl_admin WHERE user '" + txtUser + "' AND password '" + txtPwd + "'", con);
SqlCommand getuserinfo = new SqlCommand("SELECT * FROM tbl_admin WHERE user ", con);
using (SqlDataReader dr = getuserinfo.ExecuteReader())
{
while (dr.Read())
{
if ((dr["user"].ToString() == txtUserName.Text) && (dr["password"].ToString() == txtPassword.Text))
{
MessageBox.Show("Login Successful !", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Access Denied !", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUserName.Text = "";
txtPassword.Text = "";
txtUserName.Focus();
}
}
}
con.Close();
}
catch (SqlException se)
{
MessageBox.Show(se.ToString());
}
}

Answers (2)