我正在使用 C# 中的以下 SQL 查询从表 ts_dept 中检索 dept 的值 - 我将如何将其分配给Session["UserAuthentication"]
when (CurrentName != null)
?
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string username = Login_Box.UserName;
string pwd = Login_Box.Password;
string strConn;
strConn = WebConfigurationManager.ConnectionStrings["team13ConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
string sqlUserName;
sqlUserName = "SELECT dept FROM ts_dept WHERE id=@username AND pass=@pwd";
SqlCommand com = new SqlCommand(sqlUserName, Conn);
com.Parameters.Add("@username", username);
com.Parameters.Add("@pwd", pwd);
string CurrentName;
CurrentName = (string)com.ExecuteScalar();
if (CurrentName != null)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
Response.Redirect("Default.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
}