有人可以帮我吗?我的问题是,当我在下一个构造中使用 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