首页上一页 1 下一页尾页 6 条记录 1/1页
应用程序中的服务器错误。
发表在ASP.NET图书答疑
2012-04-12
是否精华
是
否
版块置顶:
是
否
“/WebSite4”应用程序中的服务器错误。
--------------------------------------------------------------------------------
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 23: {
行 24:
行 25: string sql = "update baseinfo set'%" + Session["key"].ToString() + "%', netname='" + TextBox1.Text+"'";
行 26: SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CStr"].ToString());
行 27: SqlCommand com = new SqlCommand(sql, conn);
源文件: D:\WebSite4\Default.aspx.cs 行: 25
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
_Default.Button1_Click(Object sender, EventArgs e) in D:\WebSite4\Default.aspx.cs:25
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.5448; ASP.NET 版本:2.0.50727.5456
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string i=""+Session ["ID"]+"";//接受ID
Response.Write(i );//显示要更新的行
}
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "update baseinfo set'" + Session["key"].ToString() + "', netname='" + TextBox1.Text+"'";//拼装更新语句
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CStr"].ToString());//连接字符串
SqlCommand com = new SqlCommand(sql, conn);
try
{
conn.Open();
com.ExecuteNonQuery();
}
finally
{ conn.Close(); }
if (com.ExecuteNonQuery()>0)
{ Response.Write("<script language=javascript> alert('更新成功!');location='articlemanager.aspx'</script>"); }
else
{ Response.Write("<script language=javascript> alert('更新失败!');location='articlemanager.aspx'</script>"); }
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this .BindData ();
}
}
private void BindData()
{
string sql = "select * from baseinfo ";
//string connstr = System.Configuration.ConfigurationManager.AppSettings["CStr"].ToString();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CStr"].ToString());
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
conn.Close();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
Session ["ID"]=this.GridView1.DataKeys[e.NewEditIndex].Value;//通过Session向更新页面传送要更新的行
Response.Redirect("Default.aspx");
}
}
--------------------------------------------------------------------------------
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 23: {
行 24:
行 25: string sql = "update baseinfo set'%" + Session["key"].ToString() + "%', netname='" + TextBox1.Text+"'";
行 26: SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CStr"].ToString());
行 27: SqlCommand com = new SqlCommand(sql, conn);
源文件: D:\WebSite4\Default.aspx.cs 行: 25
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
_Default.Button1_Click(Object sender, EventArgs e) in D:\WebSite4\Default.aspx.cs:25
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.5448; ASP.NET 版本:2.0.50727.5456
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string i=""+Session ["ID"]+"";//接受ID
Response.Write(i );//显示要更新的行
}
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "update baseinfo set'" + Session["key"].ToString() + "', netname='" + TextBox1.Text+"'";//拼装更新语句
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CStr"].ToString());//连接字符串
SqlCommand com = new SqlCommand(sql, conn);
try
{
conn.Open();
com.ExecuteNonQuery();
}
finally
{ conn.Close(); }
if (com.ExecuteNonQuery()>0)
{ Response.Write("<script language=javascript> alert('更新成功!');location='articlemanager.aspx'</script>"); }
else
{ Response.Write("<script language=javascript> alert('更新失败!');location='articlemanager.aspx'</script>"); }
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this .BindData ();
}
}
private void BindData()
{
string sql = "select * from baseinfo ";
//string connstr = System.Configuration.ConfigurationManager.AppSettings["CStr"].ToString();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CStr"].ToString());
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
conn.Close();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
Session ["ID"]=this.GridView1.DataKeys[e.NewEditIndex].Value;//通过Session向更新页面传送要更新的行
Response.Redirect("Default.aspx");
}
}