0

誰かが私を助けてくれますか?私の問題は、この次の構築で dataAdapter.Update を使用すると、戻り値がゼロになることです (行は更新されませんでしたが、理由やエラーは返されません)。

Accessを使用して実行すると更新文が機能し、単一のテーブルで作業すると他の更新要求が正常に機能します。

私は使用しています:vb.net \ Visual Studio 2012 \ access 2010 DB

DataGridView のデータを更新し、更新関数を呼び出します。

更新コマンド:

Private Function createGeneralUpdateStatement() As String 
Return "UPDATE EntitysDataTbl INNER JOIN ManagersExtraDataTbl ON EntitysDataTbl.entityID = ManagersExtraDataTbl.managerID " + _
"SET EntitysDataTbl.entityUserName = [@EntitysDataTbl].entityUserName, " + _
"EntitysDataTbl.entityLastEntry = [@EntitysDataTbl].entityLastEntry, " + _
"ManagersExtraDataTbl.mPassword = [@ManagersExtraDataTbl].mPassword, " + _
"ManagersExtraDataTbl.workGroup = [@ManagersExtraDataTbl].workGroup, " + _
"ManagersExtraDataTbl.entityAccessType = [@ManagersExtraDataTbl].entityAccessType, " + _
"ManagersExtraDataTbl.mActive = [@ManagersExtraDataTbl].mActive" + _
"WHERE EntitysDataTbl.entityID= [@EntitysDataTbl].entityID"
End Function

パラメータは次のとおりです。

Dim parmList(2) As String
        parmList(0) = "mPassword"
        parmList(1) = "entityUserName"

更新機能は次のとおりです。

   Public Function updateDB(ByVal updateCommand As String, ByVal parmList() As String, Optional ByVal insertCommand As String = "") As Boolean
        Dim res As Boolean = False

        SyncLock Me
            Try
                mainDataSet.EndInit()
                mUpdateCommand = New OleDb.OleDbCommand(updateCommand, MyBase.getConnector)

                For Each Str As String In parmList
                    If Not Str Is Nothing Then
                        If (Str.StartsWith("%")) Then
                            mUpdateCommand.Parameters.Add("@" & Str.Trim("%"), OleDb.OleDbType.Boolean, MAX_COL_LEN, Str.Trim("%"))
                        Else
                            mUpdateCommand.Parameters.Add("[@" & Str & "]", OleDb.OleDbType.VarChar, MAX_COL_LEN, Str)
                        End If

                    End If
                Next
                mDataAdapter.UpdateCommand = mUpdateCommand

                If (Not insertCommand.Equals("")) Then

                    mInsertCommand = New OleDb.OleDbCommand(insertCommand, MyBase.getConnector)
                    For Each Str As String In parmList
                        If Not Str Is Nothing Then
                            'If Str.Equals("RuleIDNum") Then
                            '    Continue For
                            'End If
                            If (Str.StartsWith("%")) Then
                                mInsertCommand.Parameters.Add("@" & Str.Trim("%"), OleDb.OleDbType.Boolean, MAX_COL_LEN, Str.Trim("%"))
                            Else
                                mInsertCommand.Parameters.Add("[@" & Str & "]", OleDb.OleDbType.VarChar, MAX_COL_LEN, Str)
                            End If
                        End If
                    Next
                    mDataAdapter.InsertCommand = mInsertCommand
                End If

                    Dim i As Integer = mDataAdapter.Update(mainDataSet)
    'ERROR - i = 0 => NO LINE WAS UPDATED!!!!
                    res = True
                Catch ex As Exception
                res = False
            End Try

            mDBWasUpdated = res
        End SyncLock

        Return res

    End Function
4

0 に答える 0