1

我已在表格中将这些声明为私有。

Private callLogConnection As New OleDbConnection()
Private schDataAdapter = New OleDbDataAdapter("Select * From tbl_schtime", _ callLogConnection)
Private schCommmandBuilder = New OleDbCommandBuilder(schDataAdapter)
Private schDataTable As New DataTable
Private schRowPosition As Integer = 0
Private qryexceptionDataAdapter = New OleDbDataAdapter("Select * From  _ qry_exceptionUpdate", callLogConnection)
Private exceptionBindingSource = New BindingSource()
Private exception2BindingSource As New BindingSource
Private exceptionCommandBuilder As OleDbCommandBuilder = New _ OleDbCommandBuilder(qryexceptionDataAdapter)
Private qryexceptionDataTable As New DataTable
Private qryexceptionRowPostiion As Integer = 0
Private tbl_ExceptionDataSet As DataSet = New DataSet
Private exceptionDataTable As New DataTable

我已经在表单加载中声明了这些对象

qryexceptionDataAdapter.Fill(qryexceptionDataTable)
'linking the qryexception table to binding source
exceptionBindingSource.DataSource = qryexceptionDataTable
'showing the binding source in the datagrid view
dgvExceptions.DataSource = exceptionBindingSource

这是我的保存按钮命令,用于从 datagridview 更新我的表。

Private Sub btnSaveException_Click(sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveException.Click
    Try
        Me.Validate()
        Me.qryexceptionDataAdapter.Update(Me.tbl_ExceptionDataSet.Tables("qry_exceptionUpdates"))
        Me.tbl_ExceptionDataSet.AcceptChanges()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

    End Sub code here

但我不断得到:

System.Reflection.AmbiguousMatchException: Overload resolution failed because no Public 'Update' is most specific for these arguments:
    'Public Function Update(dataTable As System.Data.DataTable) As Integer':
        Not most specific.
    'Public Overrides Function Update(dataSet As System.Data.DataSet) As Integer':
        Not most specific.
    'Public Function Update(dataRows As System.Data.DataRow()) As Integer':
        Not most specific.
   at Microsoft.VisualBasic.CompilerServices.OverloadResolution.ResolveOverloadedCall(String MethodName, List`1 Candidates, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, Boolean ReportErrors, ResolutionFailure& Failure)
   at Microsoft.VisualBasic.CompilerServices.OverloadResolution.ResolveOverloadedCall(String MethodName, MemberInfo[] Members, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, Boolean ReportErrors, ResolutionFailure& Failure)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ResolveCall(Container BaseReference, String MethodName, MemberInfo[] Members, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, Boolean ReportErrors, ResolutionFailure& Failure)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.CallMethod(Container BaseReference, String MethodName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, BindingFlags InvocationFlags, Boolean ReportErrors, ResolutionFailure& Failure)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
   at Call_Log.CallLogForm.btnSaveException_Click(Object sender, EventArgs e) in C:\Users\mdutton\Desktop\Call Log\Call Log\CallLogForm.vb:line 174
4

1 回答 1

1

线索在您的调用堆栈中:

Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall.

这意味着 VB 正试图找出它应该在运行时而不是设计时调用的重载。抛出的异常很可能意味着:

Me.tbl_ExceptionDataSet.Tables("qry_exceptionUpdates")

评估为 Nothing 因为有 3 个重载采用单个对象参数(例外已为您列出了有用的参数),这些参数可能与您的请求相匹配。

所以,这里有两件事需要解决:

1) 在项目属性中设置 Option Strict On。从微软文档

除了不允许隐式缩小转换之外,Option Strict 还会为后期绑定生成错误。当一个对象被分配给一个声明为 Object 类型的变量时,它是后期绑定的。

因为 Option Strict On 提供强类型,防止意外的类型转换和数据丢失,不允许后期绑定,并提高性能,强烈建议使用它。

2) 完成上述操作后,仍然会出现运行时错误,但现在 DataTable 参数不能为空(Nothing),因此您也需要修复此问题。

您的示例代码中可能有错字,但按钮单击事件中的表名称与您在 select 语句 ( qry_exceptionUpdatesvs _qry_exceptionUpdate) 中的名称不匹配。

如果可能,您应该在全局或模块级常量中指定一次表名,以免遇到此类命名问题。

于 2012-08-05T00:47:28.507 回答