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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Design ideas for page to add records to multiple tables (many-to-one)?

Status
Not open for further replies.

millerk

Programmer
Jul 5, 2002
133
US
Hi,
I need to build a page to add entries to several tables. There is one main table and 4 other tables that have foreign key relationships with the main table.
The primary key in the main table is auto generated.
I know I can insert into the first table, then grab the newly generated primary key value and use it to insert into the other tables.

But I'm not sure how to design a page like this and I was hoping someone had done something similar or could give me some ideas. I'm not sure if it would be better to do it step by step (insert into main table first, then let the user enter the data for the other tables) or if it would be better to build some kind of display that allows the user to enter all the data for all the tables on the same page before updating it. The second option would probably be preferable because then I could wrap everything in a transaction and not have to worry about a record getting inserted in the main table with no related data in the other tables.

I'm fairly new to ASP.Net. Is it possible to use a datagrid to allow a user to enter data in multiple rows? I was thinking I could have one set of text boxes for the values for the main table, then some kind of grid for each of the other tables to allow multiple rows to be entered.

Any ideas are appreciated.
Thanks
 
You can collect all of the information at once if you want (or do the "main" insert and follow a wizard-type procedure). With either method though you'll want a "back-out" method (which you have already identified with transactions).

Whicherver method you go with, I'd create a function and SP for each insert into the database. Call each one in turn and only commit the transaction if each one succeeds.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top