R
Rick Lederman
Using the ado.net code below to write records in an Access database, the
first three records update correctly but the last three all cause a
"Concurrency violation" error. I know that there are 6 records in the
Access database. Any ideas on what I'm doing wrong?
Rick Lederman, (e-mail address removed)
OLEDBConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
sCDatabaseName
cnFAMax = New OleDbConnection(OLEDBConnectionString)
cnFAMax.Open()
Dim i As Short
Dim MyTime As Date
sSql.Remove(0, sSql.Length)
sSql.Insert(0, "SELECT MY_EMPLOYEES.TIME_IN, MY_EMPLOYEES.EMPLOYEE_NUMBER
FROM MY_EMPLOYEES ORDER BY MY_EMPLOYEES.EMPLOYEE_NUMBER;")
Dim cmd As New OleDbCommand
cmd.CommandText = sSql.ToString
Dim da As New OleDbDataAdapter(sSql.ToString, cnFAMax)
Dim ds As New DataSet
da.Fill(ds, "My_Employees")
Dim cmdbuilder As New OleDbCommandBuilder(da)
da.InsertCommand = cmdbuilder.GetInsertCommand
da.DeleteCommand = cmdbuilder.GetDeleteCommand
da.UpdateCommand = cmdbuilder.GetUpdateCommand
For i = 0 To 5 ' I know that there are six records in this table
Select Case i
Case Is = 0
MyTime = Now
Case Is = 1
MyTime = DateAdd(DateInterval.Minute, -10, Now)
Case Is = 2
MyTime = DateAdd(DateInterval.Minute, -16, Now)
Case Is = 3
MyTime = DateAdd(DateInterval.Minute, -17, Now)
Case Is = 4
MyTime = DateAdd(DateInterval.Minute, -22, Now)
Case Is = 5
MyTime = DateAdd(DateInterval.Minute, -18, Now)
End Select
ds.Tables("My_Employees").Rows(i).Item("TIME_IN") = MyTime
Try
da.Update(ds, "My_Employees") ' the error pops up here with the
third & 4th & 5th update. Records 0 to 2 work fine
Catch ex As Exception
MsgBox("Record " & i.ToString & " " & ex.Message)
End Try
Next
first three records update correctly but the last three all cause a
"Concurrency violation" error. I know that there are 6 records in the
Access database. Any ideas on what I'm doing wrong?
Rick Lederman, (e-mail address removed)
OLEDBConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
sCDatabaseName
cnFAMax = New OleDbConnection(OLEDBConnectionString)
cnFAMax.Open()
Dim i As Short
Dim MyTime As Date
sSql.Remove(0, sSql.Length)
sSql.Insert(0, "SELECT MY_EMPLOYEES.TIME_IN, MY_EMPLOYEES.EMPLOYEE_NUMBER
FROM MY_EMPLOYEES ORDER BY MY_EMPLOYEES.EMPLOYEE_NUMBER;")
Dim cmd As New OleDbCommand
cmd.CommandText = sSql.ToString
Dim da As New OleDbDataAdapter(sSql.ToString, cnFAMax)
Dim ds As New DataSet
da.Fill(ds, "My_Employees")
Dim cmdbuilder As New OleDbCommandBuilder(da)
da.InsertCommand = cmdbuilder.GetInsertCommand
da.DeleteCommand = cmdbuilder.GetDeleteCommand
da.UpdateCommand = cmdbuilder.GetUpdateCommand
For i = 0 To 5 ' I know that there are six records in this table
Select Case i
Case Is = 0
MyTime = Now
Case Is = 1
MyTime = DateAdd(DateInterval.Minute, -10, Now)
Case Is = 2
MyTime = DateAdd(DateInterval.Minute, -16, Now)
Case Is = 3
MyTime = DateAdd(DateInterval.Minute, -17, Now)
Case Is = 4
MyTime = DateAdd(DateInterval.Minute, -22, Now)
Case Is = 5
MyTime = DateAdd(DateInterval.Minute, -18, Now)
End Select
ds.Tables("My_Employees").Rows(i).Item("TIME_IN") = MyTime
Try
da.Update(ds, "My_Employees") ' the error pops up here with the
third & 4th & 5th update. Records 0 to 2 work fine
Catch ex As Exception
MsgBox("Record " & i.ToString & " " & ex.Message)
End Try
Next