SESSION 百度说问题要长一点

来源:百度知道 编辑:UC知道 时间:2024/06/23 02:42:15
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
SqlConnection con = new SqlConnection("server=(local);uid=sa;database=showhand");
SqlCommand com = new SqlCommand("login", con);
com.Parameters.AddWithValue("@uid", Login1.UserName);
com.Parameters.AddWithValue("@pwd", Login1.Password);
com.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
if (reader["usertx"].ToString() != null)
{
Session["usertx"] = reader["usertx"].ToString();
Session["userid"] = Login1.UserName.ToString();
e.Authenticated = true;

}
else
e.Authenticated = false;

那我就看不出来哪里有问题了,但是我看你的代码,我觉得你还没有搞清楚C#的基本语法,因为当你判断一个对象是否为空时,你不能调用它的任何方法,因为当一个对象能调用方法的时候,它肯定就不是空的,所以,你这里的if (reader["usertx"].ToString() != null) {}是一种无效的写法。