使用数据库中的登录代码时出错

时间:2016-03-05 20:20:41

标签: c# asp.net sql-server login

已经定义了上面的所有连接和命令对象..

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>");
}

0 个答案:

没有答案