我有一个表名是'User_tbl',其中我保存所有注册用户的数据,并且同一张表用于在登录期间验证用户。如何在登录后更新列'datetime'
我想在登录后只更新当前日期时间的'LastSeen'列。
看这张图片。
背后
protected void Submit(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from User_tbl where UserName [email protected] and [email protected]", con);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
//to define the user seesion (starting user session)
Session["username"] = txtUserName.Text;
Response.Redirect("default2.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "LoginValidate", "<script language='javascript'> document.getElementById('errorMessage').innerHTML = 'Invalid Username or Password'</script>");
}
}
但是你没有阅读'dt'中的_that_列?也不要将您的密码存储为纯文本。阅读:http://stackoverflow.com/questions/1054022/best-way-to-store-password-in-database – 2015-02-24 12:54:39
最好不要使用AddWithValue - 请参阅http://blogs.msmvps.com/jcoehoorn/blog/ 2014/05/12/can-we-stop-using-addwithvalue-already/ – Elliveny 2015-02-24 13:12:03