我有一個表名是'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