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")

要求に一致する可能性がある単一のオブジェクト パラメーター (例外が役立つようにリストされています) を取る 3 つのオーバーロードがあるため、Nothing と評価されます。

したがって、ここで修正することが 2 つあります。

1) プロジェクトのプロパティで Option Strict On を設定します。マイクロソフトのドキュメントから:

Option Strict は、暗黙的な縮小変換を禁止するだけでなく、遅延バインディングのエラーを生成します。オブジェクトは、Object 型として宣言されている変数に割り当てられると、レイト バインドされます。

Option Strict On は厳密な型指定を提供し、データ損失を伴う意図しない型変換を防ぎ、遅延バインディングを禁止し、パフォーマンスを向上させるため、使用することを強くお勧めします。

2) 上記を実行すると、実行時エラーが発生しますが、DataTable パラメーターを null (Nothing) にすることはできないため、これも修正する必要があります。

qry_exceptionUpdatesサンプル コードにタイプミスがある可能性がありますが、ボタン クリック イベントのテーブル名が select ステートメント ( vs )のテーブル名と一致しません_qry_exceptionUpdate

可能であれば、この種の命名の問題が発生しないように、グローバルまたはモジュール レベルの定数でテーブル名を 1 回指定する必要があります。

于 2012-08-05T00:47:28.507 に答える