使用带有Gridview的objectDataSource启动ASP页时的TargetInvocationException

时间:2013-03-10 16:08:58

标签: asp.net ado.net

当我启动调试页面时,我收到以下异常。 objectDataSource是为查询oracle数据库的ADO TableAdapter配置的。然后将ods绑定到ASP.NET Gridview。我正在编写针对.NET 4.0的代码。

如果我保留gridview未绑定,则启动时没有问题。我可以完全配置ods,定义gridview的列和行行为等,并且没有问题。我(根据我的知识)使用了我过去多次成功使用的相同方法来访问和显示数据。我已尽可能仔细地阅读代码,并且无法解决问题。

异常信息:

Capabilities:Type=IE7,Name=IE,Version=7.0,MajorVersion=7,MinorVersion=0,Platform=WinNT,IsBeta=False,IsCrawler=False,IsAOL=False,IsWin16=False,IsWin32=True,SupportsFrames=True,SupportsTables=True,SupportsCookies=True,Ecmascriptversion=3.0,SupportsVBScript=True,SupportsJavaApplets=True,SupportsActiveXControls=True,CDF= False 

Inner Exception Type: System.Reflection.TargetInvocationException Inner Exception: Exception has been thrown by the target of an invocation. 
Inner Source: mscorlib 
Inner Stack Trace: at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) 
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) 
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) 
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
at System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) 
at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) 
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) 
at System.Web.UI.WebControls.DataBoundControl.PerformSelect() 
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind() 
at System.Web.UI.WebControls.GridView.DataBind() 
at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() 
at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() 

标记:

<asp:GridView ID="gvGradename" runat="server" AutoGenerateColumns="False" 
                    DataKeyNames="GRADENAME_ID" DataSourceID="odsGradename">
                    <Columns>

                        //Which columns are displayed are irrelevant. The error occurs with any columns, including none.

                    </Columns>
</asp:GridView>
<asp:ObjectDataSource ID="odsGradename" runat="server" 
                    OldValuesParameterFormatString="original_{0}" 
                    SelectMethod="GetDataByActiveName" 
                    TypeName="pts.PTSTableAdapters.PTS_GRADENAMETableAdapter">
</asp:ObjectDataSource>

查询:

select gn.gradename_id 
      , gn.mill_id
      , case when gn.gradename_id = 0 then upper(gn.name) else initcap(gn.name) end name
      , m.name millname
      , gn.audit_id
      , gn.audit_dtm
      , gn.audit_insert_dtm
      , gn.audit_process_code
      , gn.description
      , gn.roll_width_threshold
from pts_gradename gn
  , pts_mill m
where gn.is_generic = 1 
  and gn.is_active = 1
  and gn.mill_id = m.mill_id
order by case when gn.gradename_id = 0 then null else initcap(gn.name) end nulls first 

目前我在代码隐藏方面没有做任何事情。

编辑:在查询中包含了表名,以前它们已被编辑过。

此外,我可以预览表适配器中的数据,并接收预期的信息,因此查询本身似乎没有问题。

1 个答案:

答案 0 :(得分:0)

问题在于与数据表关联的自动生成的Fill方法。我无法确定究竟是什么问题,但删除它并重新开始修复问题。

这不是一个很好的答案,但它是解决这一特定问题的方法。