Dataset update error (record requires parent table record)

P

PAUL

Hello,
I have 2 datasets I am trying to update. The parent table seems to
update fine but when I go update the chiled table I get an error message
that says I need a related record in the parent table. However I put some
code in to display the key field of each parent table record (parent
dataset) and the value I am trying to put into the child table is there.

ParentTable ChildTable
ID------------------------< ParentTableID

Now because I havnt commited the transaction yet the parenttable would still
not have the new record in the DB yet, but surely it should check against
the parent table dataset not the DB?

As I said earlier all the records in the childtable dataset have related
records in the parenttable dataset so I cant understand why its
complaing....!

Any help would be appreciated...

Thanks
Paul M


'Update parent table (works ok)
daObjectsTable.DeleteCommand.Transaction = trnMain
daObjectsTable.InsertCommand.Transaction = trnMain
daObjectsTable.UpdateCommand.Transaction = trnMain
daObjectsTable.Update(dsIssue, "tblObjects")

'Update child table (fails on update)
daAffectedObjects.DeleteCommand.Transaction = trnMain
daAffectedObjects.InsertCommand.Transaction = trnMain
daAffectedObjects.UpdateCommand.Transaction = trnMain
daAffectedObjects.Update(dsIssue, "tblAffectedObjects") <---- Fails here
 
P

PAUL

Hello,
I have a dataset where in only 1 place is the data amended, however
when run the update statement:

daSomethingTable.Update(dsIssue, "tblStuff")

to get the changes back to the database using its dataadaptor I get a
concurrency exception which implies that another change was made to the same
record before update. However as I said it only gets changed in 1 specific
line (for 1 field). When I comment out that line it goes through.

Also I am the only person using the application & code on an isolated PC so
I can state categorically that no one else has the record out for edit.

Anybody got any ideas? Would be grateful for some help...

Cheers
Paul M
 
S

scorpion53061

Another problem that it could be is that the db value or type at the
source or dataset level are not the same as the other or one or the
other was changed. Check your types and length of the types to verify
they are one and the same.
 
M

Mircea Pleteriu

Hi,

I experienced the same problem.
To resolution is that you're the one which should control the update logic.
To be more clear... you need samething like:

sqlChildrenDA.Update(childrenTbl.Select(null, null,
DataViewRowState.Deleted));
sqlParentsDA.Update(parentsTbl.Select(null, null,
DataViewRowState.Deleted));

sqlChildrenDA.Update(childrenTbl.Select(null, null,
DataViewRowState.ModifiedCurrent));
sqlParentsDA.Update(parentsTbl.Select(null, null,
DataViewRowState.ModifiedCurrent));

sqlParentsDA.Update(parentsTbl.Select(null, null, DataViewRowState.Added));
sqlChildrenDA.Update(childrenTbl.Select(null, null,
DataViewRowState.Added));
 
C

Christiaan van Bergen

Hi Paul,

When I read your post correctly, you are mentioning two datasets. Why not
use one dataset with two tables and make a relation between those tables
(foreign-key constraint). In that way the data is indeed checked (if
enforceconstraints is set to true)

If you are using two datasets, consider committing the transaction where you
update/insert the parent table. Because in case of two datasets, the only
check you have in your dataadapter is against the database.

Hope this helps,

Cheers
Christiaan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top