0

Already define all connection and command object above..

SqlCommand cmd = new SqlCommand("select COUNT(*) FROM User where username='"+txtUsername .Text +"'and password='"+txtPassword .Text +"'", con);

Here is my Code

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataTable dt = new DataTable;
da.Fill(dt);

if (dt.Rows.Count > 0)
{
    Response.Write("logged In");
}
else
{
    Response.Write("<script>alert('Please enter valid Username and Password');</script>");
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 3
    look it is not a good idea to make a login like this . this is very dangerous because of injection and if u wanna to make a login read this it is very easy way and it is safe http://www.aspsnippets.com/Articles/Simple-User-Login-Form-example-in-ASPNet.aspx – banksy Mar 05 '16 at 20:28
  • Please specify what error occured. Does it simply not work or is an exception thrown? And from a security perspective this is really creepy: please read up on [sql parameters](http://stackoverflow.com/questions/7505808/why-do-we-always-prefer-using-parameters-in-sql-statements) and [password hashing](http://crypto.stackexchange.com/questions/24/what-makes-a-hash-function-good-for-password-hashing). And if that sounds to complicated, use an authentication middleware - depending on the asp.net framework you use. – ventiseis Mar 05 '16 at 21:12
  • da.Fill(dt) " incorect syntex near keyword User" – Umang Patel Mar 05 '16 at 21:14

0 Answers0