我在登录页面中编写了此代码。我的代码没有任何错误,但更新查询不适用于我的数据库。
拳头查询有效,我重定向到index.aspx
但更新查询(第二个查询)不适用!!!!
protected void btnLogin_Click(object sender, EventArgs e)
{
Database db1 = new Database();
string query = "select * from Admins where UserName=@username and cast(Password as varbinary)=cast(@password as varbinary)";
SqlCommand smd = new SqlCommand(query, db1.sc);
smd.Parameters.AddWithValue("@username", txtUsername.Text);
smd.Parameters.AddWithValue("@password", General.CreatePasswordHash(txtPassword.Text));
SqlDataReader sdr = smd.ExecuteReader();
smd.Parameters.Clear();
if (sdr.Read())
{
Session.Add("username", sdr[0].ToString());
string nowEnter = sdr[5].ToString();
query = "update Admins set LastEnter=@lastEnter, NowEnter=@nowEnter where UserName=@username";
string now = General.getPersianDateNow() + " ساعت " + General.getPersianTimeNow();
smd.CommandText = query;
smd.Parameters.AddWithValue("@lastEnter", nowEnter);
smd.Parameters.AddWithValue("@nowEnter", now);
smd.Parameters.AddWithValue("@username", sdr[1].ToString());
sdr.Close();
smd.ExecuteNonQuery();
Response.Redirect("~/admin/Index.aspx", false);
}
else
{
lblError.Visible = true;
}
}