心塞表情包:异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 21:10:50
源错误:

行 20: {
行 21:
行 22: string srtusername=Request.Form["username"].ToString();
行 23: string srtuserlove=Request.Form["userpwd"].ToString();
行 24:

源文件: f:\我的网络\webapplication1\webform2.aspx.cs 行: 22

堆栈跟踪:

[NullReferenceException: 未将对象引用设置到对象的实例。]
WebApplication1.WebForm2.Page_Load(Object sender, EventArgs e) in f:\我的网络\webapplication1\webform2.aspx.cs:22
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace WebApplication3
{
public class WebForm2 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string username=Request.Form["username"].ToString();
string userpwd=Request.Form["userpwd"].ToString();
SqlConnection con=new SqlConnection("server=.;database=login;uid=sa;pwd=;");
con.Open();
SqlCommand cmd=new SqlCommand("select count(*) from login where username='"+username+"' and userpwe='"+userpwd+"'",con);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
Response.Write("登陆成功");

}
else
{
Response.Write("登陆失败");

}
}
}
}

这样不详细,把这一段代码列出来看看(有没有把Request放在PageLoad中?)