Is this a case for Transactions?

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Hi guys,

I've been reading Microsoft ADO.Net as a resource book as I have been designing and building projects for my company.

However, there is one thing that hasn't been fully explained in the book, either in the text or on the examples on CD.

a lot of my code is based on the code in the book, so could explain if this isn't a normal problem!

When my form brings back my master child data (child shown in a datagrid) and I want to add a new record, I have my master data ID set to Autoincrement set to true, and Autoincrement Seed and Step set to -1.
Therefore when a new record is added, the value displayed is not the true autoincrement from SQL (this label is hidden until they have submitted to the DB and then the real value shows).

Anyway, point is, when I add a new record, fill in the information, and then add the child data, and submit to the database, the system errors. It has something to do with the Child Data not having a parent existing in the parent table. This makes sense, as from what I understand a parent has to exist before a child can be added.

I opened the example from the CD and it does exactly the same error. However, on the last example on the CD (not explained in the book), the error does not happen, and a user can add master and child data and submit OK. The only difference in the code is that the latter example uses Transactions.

SOOOOOOOOOOO (finally) my question is, for my users to be able to add master child data without having the errors I'm experiencing, should I be updating to the database using transactions?

I've even tried to use the DataForm Wizard code and still have the same problems.
One way around it is to add the master data first, then submit to the database, then add the child data. However my users will not like this so I want to be able to do it in one swift move if possible!

Thanks!
Luke
 
Back
Top