本人今天遇到一个非常奇怪的问题,大体情况以下:
用OleDbDataAdapter来取得数据,然后绑定到DataGrid。
错误情况:如果方法getSQL()中返回比较长的那个SQL语句,出现错误。如果返回段的查询语句,没有错误。 错误:
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 41: conn = New OleDbConnection(connstr)
行 42: DA = New OleDbDataAdapter(getSQL(), conn)
行 43: DA.Fill(DS)
行 44:
行 45: DGSwitchRout.DataSource = DS.Tables(0).DefaultView
源文件: c:\inetpub\wwwroot\Test\WebForm1.aspx.vb 行: 43
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
System.Data.Common.ICommandText.Execute(IntPtr pUnkOuter, Guid riid, tagDBPARAMS pDBParams, Int32& pcRowsAffected, Object& ppRowset) +0
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForMultpleResults(tagDBPARAMS dbParams, Object& executeResult) +82
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +62
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +69
System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +5
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +38
Test.WebForm1.BindData() in c:\inetpub\wwwroot\Test\WebForm1.aspx.vb:43
Test.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Test\WebForm1.aspx.vb:30
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
源代码以下:
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class WebForm1
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
Protected WithEvents DGSwitchRout As System.Web.UI.WebControls.DataGrid '注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not Page.IsPostBack Then
BindData()
End If
End Sub '绑定数据
Private Sub BindData()
Dim connstr As String
Dim SQL As String
Dim conn As OleDbConnection
Dim DA As OleDbDataAdapter
Dim DS As New DataSet connstr = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")
conn = New OleDbConnection(connstr)
DA = New OleDbDataAdapter(getSQL(), conn)
DA.Fill(DS) DGSwitchRout.DataSource = DS.Tables(0).DefaultView
DGSwitchRout.DataBind() End Sub '以下代码用于取得查询语句
Private Function getSQL() As String
getSQL = "select to_char(stat_time,'yyyy-mm-dd') stat_time,'全网' name," & _
" case t_calls when 0 then 0 else round(T_SUCcESS_CALLS/T_CALLS*100,2) end T_LINK_RATIO," & _
" case t_calls when 0 then 0 else round(T_JAM_CALLS/T_CALLS*100,2) end T_JAM_RATIO," & _
" case t_def_channel when 0 then 0 else round(T_CHANNEL/T_DEF_CHANNEL*100,2) end T_SHATTER_RATIO," & _
" case t_success_calls when 0 then 0 else round(T_DROP_CALLS/T_SUCcESS_CALLS*100,2) end T_DROP_RATIO," & _
" case (t_sqi_good+t_Sqi_Accept+t_sqi_bad) when 0 then 0 else round(T_SQI_GOOD/(T_SQI_GOOD+ T_SQI_ACCEPT+T_SQI_BAD)*100,2) end T_GOOD_RATIO," & _
" case t_channel when 0 then 0 else round(T_TRAFFIC/T_CHANNEL,2) end T_CHN_TRA," & _
" case t_success_calls when 0 then 0 else round(T_TRAFFIC/T_SUcCESS_CALLS * 3600) end T_HOLD_TIME," & _
" case c_calls when 0 then 0 else round(c_SUCcESS_CALLS/C_CALLS*100,2) end C_LINK_RATIO," & _
" case c_calls when 0 then 0 else round(C_JAM_CALLS/C_CALLS*100,2) end C_JAM_RATIO," & _
" case c_def_channel when 0 then 0 else round(C_CHANNEL/C_DEF_CHANNEL*100,2) end C_SHATTER_RATIO," & _
" case c_success_calls when 0 then 0 else round(C_DROP_CALLS/C_SUcCESS_CALLS*100,2) end C_DROP_RATIO," & _
" case c_channel when 0 then 0 else round(C_TRAFFIC/C_CHANNEL,2) end C_CHN_TRA," & _
" case KPI_ATTEMPT_CALLS when 0 then 0 else round(KPI_SUCC_CALLS/KPI_ATTEMPT_CALLS*100,2) end CALL_SUCC," & _
" case KPI_ATTACH_USERS when 0 then 0 else round(KPI_JAM_TIMES/KPI_ATTACH_USERS,2) end KPI_JAM," & _
" case KPI_ATTACH_USERS when 0 then 0 else round(KPI_DROP_TIMES/KPI_ATTACH_USERS,2) end KPI_DROP," & _
" case (KPI_GOOD_TIMES+KPI_NORMAL_TIMES+ KPI_BAD_TIMES) when 0 then 0 else round((KPI_GOOD_TIMES+0.5*KPI_NORMAL_TIMES)/(KPI_GOOD_TIMES+KPI_NORMAL_TIMES+ KPI_BAD_TIMES)*100,2) end KPI_CALL_QUALITY," & _
" case (istrue+isfalse) when 0 then 0 else round(istrue/(istrue+isfalse) * 100,2) end TRUE_RATIO" & _
" from allnet_tel_day where stat_time>=date '2005-5-1' and stat_time<=date '2005-8-1'" 'getSQL = "select * from allnet_tel_day where stat_time>=date '2005-5-1' and stat_time<=date '2005-8-1'"//如果换成这个语句,没有错误。 End Function
End Class
用OleDbDataAdapter来取得数据,然后绑定到DataGrid。
错误情况:如果方法getSQL()中返回比较长的那个SQL语句,出现错误。如果返回段的查询语句,没有错误。 错误:
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 41: conn = New OleDbConnection(connstr)
行 42: DA = New OleDbDataAdapter(getSQL(), conn)
行 43: DA.Fill(DS)
行 44:
行 45: DGSwitchRout.DataSource = DS.Tables(0).DefaultView
源文件: c:\inetpub\wwwroot\Test\WebForm1.aspx.vb 行: 43
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
System.Data.Common.ICommandText.Execute(IntPtr pUnkOuter, Guid riid, tagDBPARAMS pDBParams, Int32& pcRowsAffected, Object& ppRowset) +0
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForMultpleResults(tagDBPARAMS dbParams, Object& executeResult) +82
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +62
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +69
System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +5
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +38
Test.WebForm1.BindData() in c:\inetpub\wwwroot\Test\WebForm1.aspx.vb:43
Test.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Test\WebForm1.aspx.vb:30
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
源代码以下:
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class WebForm1
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
Protected WithEvents DGSwitchRout As System.Web.UI.WebControls.DataGrid '注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not Page.IsPostBack Then
BindData()
End If
End Sub '绑定数据
Private Sub BindData()
Dim connstr As String
Dim SQL As String
Dim conn As OleDbConnection
Dim DA As OleDbDataAdapter
Dim DS As New DataSet connstr = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")
conn = New OleDbConnection(connstr)
DA = New OleDbDataAdapter(getSQL(), conn)
DA.Fill(DS) DGSwitchRout.DataSource = DS.Tables(0).DefaultView
DGSwitchRout.DataBind() End Sub '以下代码用于取得查询语句
Private Function getSQL() As String
getSQL = "select to_char(stat_time,'yyyy-mm-dd') stat_time,'全网' name," & _
" case t_calls when 0 then 0 else round(T_SUCcESS_CALLS/T_CALLS*100,2) end T_LINK_RATIO," & _
" case t_calls when 0 then 0 else round(T_JAM_CALLS/T_CALLS*100,2) end T_JAM_RATIO," & _
" case t_def_channel when 0 then 0 else round(T_CHANNEL/T_DEF_CHANNEL*100,2) end T_SHATTER_RATIO," & _
" case t_success_calls when 0 then 0 else round(T_DROP_CALLS/T_SUCcESS_CALLS*100,2) end T_DROP_RATIO," & _
" case (t_sqi_good+t_Sqi_Accept+t_sqi_bad) when 0 then 0 else round(T_SQI_GOOD/(T_SQI_GOOD+ T_SQI_ACCEPT+T_SQI_BAD)*100,2) end T_GOOD_RATIO," & _
" case t_channel when 0 then 0 else round(T_TRAFFIC/T_CHANNEL,2) end T_CHN_TRA," & _
" case t_success_calls when 0 then 0 else round(T_TRAFFIC/T_SUcCESS_CALLS * 3600) end T_HOLD_TIME," & _
" case c_calls when 0 then 0 else round(c_SUCcESS_CALLS/C_CALLS*100,2) end C_LINK_RATIO," & _
" case c_calls when 0 then 0 else round(C_JAM_CALLS/C_CALLS*100,2) end C_JAM_RATIO," & _
" case c_def_channel when 0 then 0 else round(C_CHANNEL/C_DEF_CHANNEL*100,2) end C_SHATTER_RATIO," & _
" case c_success_calls when 0 then 0 else round(C_DROP_CALLS/C_SUcCESS_CALLS*100,2) end C_DROP_RATIO," & _
" case c_channel when 0 then 0 else round(C_TRAFFIC/C_CHANNEL,2) end C_CHN_TRA," & _
" case KPI_ATTEMPT_CALLS when 0 then 0 else round(KPI_SUCC_CALLS/KPI_ATTEMPT_CALLS*100,2) end CALL_SUCC," & _
" case KPI_ATTACH_USERS when 0 then 0 else round(KPI_JAM_TIMES/KPI_ATTACH_USERS,2) end KPI_JAM," & _
" case KPI_ATTACH_USERS when 0 then 0 else round(KPI_DROP_TIMES/KPI_ATTACH_USERS,2) end KPI_DROP," & _
" case (KPI_GOOD_TIMES+KPI_NORMAL_TIMES+ KPI_BAD_TIMES) when 0 then 0 else round((KPI_GOOD_TIMES+0.5*KPI_NORMAL_TIMES)/(KPI_GOOD_TIMES+KPI_NORMAL_TIMES+ KPI_BAD_TIMES)*100,2) end KPI_CALL_QUALITY," & _
" case (istrue+isfalse) when 0 then 0 else round(istrue/(istrue+isfalse) * 100,2) end TRUE_RATIO" & _
" from allnet_tel_day where stat_time>=date '2005-5-1' and stat_time<=date '2005-8-1'" 'getSQL = "select * from allnet_tel_day where stat_time>=date '2005-5-1' and stat_time<=date '2005-8-1'"//如果换成这个语句,没有错误。 End Function
End Class
解决方案 »
- 关于泛型 求解
- 一千人同时提交数据
- 自定义MembershipProviderd 的问题
- 在C#+ASP.NET中怎样加载MENU(菜单)控件?
- 怎么在ASP。NET页面中,打开MSN对话框聊天。。????谢谢
- Visio生成的Access数据库表不能使用
- 如何得到组合控件的子控件的ID?
- IE如何访问客户端的设备(比如COM口的读卡器)
- 页面能访问,点击提交按钮提示http405错误,输入完整网址才能提交
- 按了删除键后怎么先弹出一个框框警告要不要删除?
- 指教:如何读取一个图片类型的文件,并将其内容保存到ORACLE数据库中,数据库字段类型为BLOB.谢谢!谢谢!
- Visual Studio.NET为什么总是自以为是???
比如to_char建议跟踪sql
然后到查询分析器里一看就知道了
还有一个问题,如果在错误的页面中,刷行多次,会造成aspnet_wp.exe线程CUP占用率高达98%,也无法运行其他页面了。
估计还是sQL语句的问题
你可在这一句
End Function
之上再写一句me.response.write(getSQL)
End Function把SQL语句打印出来之后,拿到数据库中去运行一下。
1、有时候编译完,弹出一个对话框,大体意思是说,JIT调试失败
2、如果在错误页中,多次刷新,出现的错误信息会不同,同时会造成线程aspnet_wp.exe占用CUP非常高
3、如果将SQL语句在分析器中运行正常,如果SQL语句出现错误,错误提示会出现oracle的异常。说明是执行查询后才出现的错误。
4、如果把SQL语句换成View,运行正常以上就是我所遇到的情况,请大家给分析一下。谢谢!
.NET?才入门而已!!!
===============================================
不要问我是谁,茫茫人海中我们曾擦肩而过。
不要问我是谁,滚滚红尘中我们曾经相识过!
不要问我是谁,茫茫人海中那一抹蓝色就是我的星座,
不要问我是谁,我也不知我们相识相知到底是对是错!
===============================================