J
John
Hi
I have developed the following logic to handle db concurrency violations. I
just wonder if someone can tell me if it is correct or if I need a
different approach.Would love to know how pros handle it.
Thanks
Regards
Dim dc As DataColumn
Dim drCache As DataRow
Dim drCurrent As DataRow
Try
' Attempt the update
daContacts.Update(ds.Contacts)
Catch Ex As DBConcurrencyException
' First - cache the row
drCache = ds.Contacts.NewRow()
For Each dc In ds.Contacts.Columns
If Not dc.ReadOnly Then
drCache(dc.ColumnName) = Ex.Row(dc.ColumnName)
End If
Next
' Refresh from database
daContacts.Fill(ds.Contacts)
' Position to the faulted row
drCurrent = ds.Contacts.Rows.Find(Ex.Row("ID"))
' Apply User Changes
For Each dc In ds.Contacts.Columns
If Not dc.ReadOnly Then
drCurrent(dc.ColumnName) = drCache(dc.ColumnName)
End If
Next
' Save again
daContacts.Update(ds.Contacts)
End Try
I have developed the following logic to handle db concurrency violations. I
just wonder if someone can tell me if it is correct or if I need a
different approach.Would love to know how pros handle it.
Thanks
Regards
Dim dc As DataColumn
Dim drCache As DataRow
Dim drCurrent As DataRow
Try
' Attempt the update
daContacts.Update(ds.Contacts)
Catch Ex As DBConcurrencyException
' First - cache the row
drCache = ds.Contacts.NewRow()
For Each dc In ds.Contacts.Columns
If Not dc.ReadOnly Then
drCache(dc.ColumnName) = Ex.Row(dc.ColumnName)
End If
Next
' Refresh from database
daContacts.Fill(ds.Contacts)
' Position to the faulted row
drCurrent = ds.Contacts.Rows.Find(Ex.Row("ID"))
' Apply User Changes
For Each dc In ds.Contacts.Columns
If Not dc.ReadOnly Then
drCurrent(dc.ColumnName) = drCache(dc.ColumnName)
End If
Next
' Save again
daContacts.Update(ds.Contacts)
End Try