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.Upda te(ds.Contacts)
Catch Ex As DBConcurrencyEx ception
' First - cache the row
drCache = ds.Contacts.New Row()
For Each dc In ds.Contacts.Col umns
If Not dc.ReadOnly Then
drCache(dc.Colu mnName) = Ex.Row(dc.Colum nName)
End If
Next
' Refresh from database
daContacts.Fill (ds.Contacts)
' Position to the faulted row
drCurrent = ds.Contacts.Row s.Find(Ex.Row(" ID"))
' Apply User Changes
For Each dc In ds.Contacts.Col umns
If Not dc.ReadOnly Then
drCurrent(dc.Co lumnName) = drCache(dc.Colu mnName)
End If
Next
' Save again
daContacts.Upda te(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.Upda te(ds.Contacts)
Catch Ex As DBConcurrencyEx ception
' First - cache the row
drCache = ds.Contacts.New Row()
For Each dc In ds.Contacts.Col umns
If Not dc.ReadOnly Then
drCache(dc.Colu mnName) = Ex.Row(dc.Colum nName)
End If
Next
' Refresh from database
daContacts.Fill (ds.Contacts)
' Position to the faulted row
drCurrent = ds.Contacts.Row s.Find(Ex.Row(" ID"))
' Apply User Changes
For Each dc In ds.Contacts.Col umns
If Not dc.ReadOnly Then
drCurrent(dc.Co lumnName) = drCache(dc.Colu mnName)
End If
Next
' Save again
daContacts.Upda te(ds.Contacts)
End Try
Comment