Still Getting Concurrency Issues when Updating DataAdapter

  • Thread starter Thread starter Lee Ottaway
  • Start date Start date
L

Lee Ottaway

I have read various threads relating to concurrency issues in ADO.NET
and thought when I implemented the info I found that my problems would
be solved, however I'm still getting concurrency issues. Can anyone
tell me what's wrong with this code:

This is the DataAdapter handler I've implemented to get the Primary
Key information from the AutoIncremented field 'ID' for new records in
my single table called tblStaff:

Private Sub HandleUpdate(ByVal sender As Object, ByVal e As
OleDbRowUpdatedEventArgs) Handles madp.RowUpdated

If e.StatementType = StatementType.Insert Then
Dim getKey As New OleDbCommand("SELECT @@IDENTITY", gCon)
e.Row("ID") = getKey.ExecuteScalar
getKey.Dispose()
End If

End Sub

I can then add a record with no problem and the e.Row("ID") is getting
the correct value for the ID. However, when I edit and update the
same record with the following:

Dim frm As New frmStaffDlg()
Dim dv As New DataView(mds.Tables("tblStaff"))
Dim row As DataRowView

row = dv.AddNew()
frm.DataRowView = row
If frm.ShowDialog() = DialogResult.OK Then
madp.Update(mds, "tblStaff")
mds.AcceptChanges()
End If

It comes up with a concurrency issue and tells me no records have been
updated. The strange thing is that the ID is correct in the
dataset.tables("tblStaff").Columns("ID"). What on earth am I doing
wrong???

I'm using Access 2002 by the way so I know there's no problem with the
"SELECT @@IDENTITY" CALL.
 
My Reply to myself from an earlier problem. THis may help.

False alarm, the real problem is a bit more tricky. It was
actually a double field causing the problem. While the
data adapter wizard honors the default settings (ie
default value of 0) of the fields when it creates the
dataset and associated code from a jet database, the
automatic update query it generates does not, so the end
result is an insert works fine (although no default value
is established unless you code for it) but the update
fails because unless the field has a value in it (ie it is
still NULL) the update will fail as the code is only
generated for a value. It assumes the default value has
been applied. Basic rule, dont rely on Jet engine to set
defaults and dont establish the database with defaults as
it wont work if you leave the fields in a NULL state when
you later attempt to update the records.

HTH someone.

Phil
 
Back
Top