Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best practice of saving parent/child data from a data entry form

Status
Not open for further replies.

JanVolley

Programmer
Sep 8, 2008
14
US
I'm using asp.net 2.0 and C#. I have a data entry web form that contains a formview that is bound to a cpDataSource. The cpDataSource specifies an 'InsertMethod' that is contained in a db access class.

The web form contains alot of textboxes but also contains two CheckBoxList's. Each CheckBoxList is associated with a child table. When the user clicks the 'Save' button, the data in the form will get saved to the database via the 'InsertMethod' that calls a stored procedure in the database (SQLServer). This saves the parent data on the form. I then have a cpDataSource_Inserted method defined OnInsert that will cycle through each CheckBoxList and save the child records accordingly if the checkboxes are checked.

My question is: This method that I am using works, but if the db were to go down after the parent data is saved but before the child data is saved, I will have inconsistent data in the database. Is there a better way of doing this?

I could have the stored procedure save everything and start a transaction at the beginning. I'm rusty on SQLServer so not sure if you can do that, but I wanted to find out the best practice in doing this standard type of thing.

Thanks,
Jan
 
I find session per view is a great tool for web development. this is very common with nhibernate and activerecord, but the concept can be applied to raw ado objects as well..

in a nutshell you have an object which is responsible for the connection/transaction. at the beginning of the request you open the connection. at the end of the request you close the connection. during the request you access the connection manager to preform any db commands necessary. transaction management can be as simple or as complex as you like.

once you have a basic object working you can begin to refine the connection manager (only opening when necessary. only running transactions during IUD operations.)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Your link doesn't really go anywhere. Not sure I understand what this is. Is this a product or a design pattern?
 
the link points to articles on the subject. Session per view is a design pattern.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top