我连的一个数据库总是报这个错,请各位帮忙看一下,指点我一下,看看该改什么东西异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 41:
行 42: tabOne = new DataTable();
行 43: tabOne = dataSet.Tables["School_Memorabilias"];
行 44: if (tabOne == null || tabOne.Rows.Count == 0)
行 45: {
源文件: e:\aspx\school\memorabiliashow.aspx.cs 行: 43 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
Tvo.Clinet.School.MemorabiliaShow.Page_Load(Object sender, EventArgs e) in e:\aspx\school\memorabiliashow.aspx.cs:43
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
行 41:
行 42: tabOne = new DataTable();
行 43: tabOne = dataSet.Tables["School_Memorabilias"];
行 44: if (tabOne == null || tabOne.Rows.Count == 0)
行 45: {
源文件: e:\aspx\school\memorabiliashow.aspx.cs 行: 43 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
Tvo.Clinet.School.MemorabiliaShow.Page_Load(Object sender, EventArgs e) in e:\aspx\school\memorabiliashow.aspx.cs:43
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
tabOne = dataSet.Tables["School_Memorabilias"];
你可以跟踪一下,看看dataset是否为null,要知道若是为null的话,怎么可能有里面的表呢?另外,就代码的健壮性来说,给楼主一个建议,我通常在这种场合都会更勤奋地加上一句代码,如下:
if(null!=dataSet)
tabOne = dataSet.Tables["School_Memorabilias"];这样就不会那么容易出硬性错误了。