“/Test2-1”应用程序中的服务器错误。
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 19: private void Page_Load(object sender, System.EventArgs e)
行 20: {
行 21: string userName=Request.Form.Get("userName").ToString();
行 22: string userPwd=Request.Form.Get("userPwd").ToString();
行 23:
源文件: c:\inetpub\wwwroot\test2-1\login.aspx.cs 行: 21 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
Test2_1.Login.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\test2-1\login.aspx.cs:21
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
我死活找不出错在哪帮忙看看 谢谢~
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 19: private void Page_Load(object sender, System.EventArgs e)
行 20: {
行 21: string userName=Request.Form.Get("userName").ToString();
行 22: string userPwd=Request.Form.Get("userPwd").ToString();
行 23:
源文件: c:\inetpub\wwwroot\test2-1\login.aspx.cs 行: 21 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
Test2_1.Login.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\test2-1\login.aspx.cs:21
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
我死活找不出错在哪帮忙看看 谢谢~
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Test2_1
{
/// <summary>
/// Login 的摘要说明。
/// </summary>
public class Login : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string userName=Request.Form.Get("userName").ToString();
string userPwd=Request.Form.Get("userPwd").ToString();
SqlConnection con=new SqlConnection("server=.;database=login;uid=sa;pwd=108;");
con.Open();
SqlCommand cmd=new SqlCommand("select count (*) from login where userName='"+userName+"'and userPwd='"+userPwd+"'",con);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
Response.Redirect("main.aspx");
}
else{
Response.Redirect("loginFail.htm");
}
// 在此处放置用户代码以初始化页面
}
string userPwd=Request.Form.Get("userPwd").ToString();
应该在 !IsPostBack 里面
2.同意 skytear() 的说法