【问题标题】:vb 2010, deleting rows in datagridview to update access tablevb 2010,删除datagridview中的行以更新访问表
【发布时间】:2012-08-04 23:32:58
【问题描述】:

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

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

【问题讨论】:

  • 什么时候出现这个错误?在页面加载期间或单击提交按钮时

标签: vb.net ms-access datagridview oledb


【解决方案1】:

线索在你的调用堆栈中:

Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall.

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

Me.tbl_ExceptionDataSet.Tables("qry_exceptionUpdates")

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

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

1) 在项目属性中设置 Option Strict On。来自Microsoft Documentation

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

因为 Option Strict On 提供强类型,防止意外 具有数据丢失的类型转换,不允许后期绑定,并改进 性能,强烈推荐使用它。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多