只有10分了,一个入门级问题,谢谢讲解...
我做个login功能,准备用login.htm页面为登录界面,login.aspx为处理登录的程序文件,用户名和密码存在sql2000数据库里的。
测试报错:
未将对象引用设置到对象的实例。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 15: protected void Page_Load(object sender, EventArgs e)
行 16: {
行 17: string userName = Request["userName"].ToString();
行 18: string userPwd = Request["userPwd"].ToString();
login.aspx文件的代码如下:
protected void Page_Load(object sender, EventArgs e)
{
string userName = Request.Form["userName"].ToString();
string userPwd = Request.Form["userPwd"].ToString();
string sqlConnString = "server=.;database=login;user=sa;pwd=sa;";
string sqlComString = "select count(*) from login where userName='" + userName + "'and userPwd='" + userPwd + "'";
SqlConnection sqlConn = new SqlConnection(sqlConnString);
sqlConn.Open();
SqlCommand sqlCom = new SqlCommand(sqlComString, sqlConn);
int count = Convert.ToInt32(sqlCom.ExecuteScalar());
if (count > 0)
{
Response.Redirect("main.aspx");
}
else
{
Response.Redirect("login.htm");
}
}
如果把sql的处理语句去掉,用response.write(userName+","+userPwd)是可以写出用户名和密码的,但是一加上后的处理语句,就出错。
应该是小个问题吧,哪位帮帮忙,讲一下哪里错了??