|
-
Mar 22nd, 2024, 10:24 AM
#1
Thread Starter
New Member
DBConcurrencyException Error
I have a multi-user application developed with VB Community 2019. The data in the seven tables displayed on one form are retrieved from an SQL database using separate dataadapters and then filling a local dataset (DS). All tables are related by adding a relationship to the dataset DS:
Code:
DS.Relations.Add("RPO", DS.Tables("Jobs").Columns("ID"), DS.Tables("POs").Columns("JobID"), False)
BS.DataSource = DS
BS.DataMember = "Jobs"
Me.BindingNavigator1.BindingSource = BS
BSPos.DataSource = BS
BSPos.DataMember = "RPO"
Note the child constraint is not set. When this form is closed, all tables in the dataset DS are saved back to the underlying database using each table's dataadapter. This is the code for saving the data in the one table (they are all similar):
Code:
DAPO.Update(DS.Tables("POs"))
Immediately after the above line of code, I check to see if there has been any DBConcurrencyExceptions as follows:
Code:
Catch DBEX As DBConcurrencyException
Dim TmpTbl As DataTable = GetDBRow("POs", "RecID", DBEX.Row.Item("RecID"))
DS.Tables("POs").PrimaryKey = {DS.Tables("POs").Columns("RecID")}
DS.Tables("POs").Merge(TmpTbl, True)
The GetDBRow is simply a function that retrieves the offending row from the underlying database table into a local datatable and sets the Primary Key for that table. Then if that works, the Primary Key on the tables "POs" is set, the two tables are merged, and then the update completes successfully.
The issue I am having is when that function is called, occassionally I get an error on that line saying conversion from type 'DBNull' to type 'Integer' is not valid which must mean the DBEX object returned from the DBConcurrrencyException has a null value in the primary key "RecID".
I have verified that the primary key in that table is set as the primary key which allows no null values and querying all rows in that table for any rows that contain Null in the primary key column returns no rows. There are null values in some of the other columns of that table, but I don't think this should matter.
How can the offending row returned from the object "DBEX" have a null value in the primary key column, or does the error mean something else.
I really hope someone can help with this issue because when it happens, all changes made by the user to that table are NOT saved. And I am completely stumped! HELP, please. Is the fact that I am not setting the child constraint in the DS relationship causing this issue
Larry
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|