登陆代码问题,请高手指教!!!

来源:百度知道 编辑:UC知道 时间:2024/06/24 07:34:30
string strsql = "update company set logintime='" + System.DateTime.Now.ToString() + "' where name='" + Text1.Value + "'and password='" + Password1.Value + "'";
SqlCommand cm = new SqlCommand(strsql, conn);
cm.Connection.Open();
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
Session["UserName"] = Text1.Value;
Session["UserID"] = dr["companyID"];
Session["companyname"] = dr["companyname"];
Session["UserType"] = RadioButtonList1.SelectedIndex;
Response.Redirect("company.aspx");
}
else
{ Response.Write("<script language='javascript'>alert('对不起,您的登录名或密码不符!');location.href='main.aspx


SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
改为
int iRow = cm.ExecuteNonQuery();
if(iRow>0)

ExecuteNonQuery()方法是返回所更新的记录数

欢迎沟通交流

cm.ExecuteReader(); 执行查询语句时有返回值,你的sql语句中并不包含查询语句,dr对象中当然没有东西了,dr.Read()永为假。