Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2006, 09:09 PM
Authorized User
 
Join Date: Feb 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting a record and contents in multiple tables

Hello,

i'm wondering if this is possible...

Ok, right

Well i want to create an admin page which will insert new entries into a database, sounds easy right? all i need to do is use form view or details view and set insert to true.

however each record defination is spread over many tables. say i am doing a cook book and i have one table for the recipes and one table for the ingredients recipe_ingredients and then a third table which lists the ingredients available. I wish to allow the admin to insert a new recipe and on that page bring back the list of ingredients (with the option to add a new one if necessary) which will be associated with the recipe_id into the recipe_ingredients table as well. I am not sure which out of detailsview and formview it is best to use.

any help would be appreciated

 
Old March 29th, 2006, 01:00 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

A detailsview or formview shows records from a single table. You will need to use a gridview to do wha you want. You will then need to specify your own select, insert, update and delete statments for the sqldatasoruce.

Jim

 
Old March 31st, 2006, 06:06 PM
Authorized User
 
Join Date: Feb 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi i've been working on this problem a bit and decided not to use formview or details view but rather use sqldatasources to retrieve the data from textboxes and create insert statements manually,

then on the buttonclick i just called sqldatasource1.insert and this works fine for one of the tables creating a new recipe_ID. However on this button click i also want to insert the recipe_ID i've just created into another table so it can be used to insert the rest of the data. The queryparameter doesn't work as i'm not passing the variable from another page. would i need to create it as a session variable and then pass it into the insert statement? is so are there any examples i would be able to use?

many thanks,

michelle

 
Old March 31st, 2006, 06:44 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Insert the first row.. reurun the id just created.. then use that in your second insert...

 
Old April 2nd, 2006, 11:20 AM
Authorized User
 
Join Date: Feb 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry to bother you again, but i've been trying to return the id i've just created but it doesn't work and i haven't been able to insert it into my second sqldatasource. i tried creating a max select statement and putting it in a label which i then tried to put into the db but that too was unsuccessful.

 
Old May 13th, 2006, 04:23 AM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Shell84
 Sorry to bother you again, but i've been trying to return the id i've just created but it doesn't work and i haven't been able to insert it into my second sqldatasource. i tried creating a max select statement and putting it in a label which i then tried to put into the db but that too was unsuccessful.

I've just done something similar that seems to work.

Presuming cmd = new SqlCommand()


Try this as your Insert statement for table one

Code:
cmd.Command = "INSERT INTO Invoices (InvDate, ClientID) VALUES (@InvDate, @ClientID) SELECT SCOPE_IDENTITY()"
add your Parameters and set their values etc then

Code:
dim InvoiceID as Integer
InvoiceID = cmd.ExecuteScaler()
InvoiceID will now hold the Primary Key for the table just written to. You can now change your focus to other tables and utilise this variable for their relationships. I used

Code:
cmd.ExecuteNonQuery()
 for these.

Hope this helps


 
Old August 15th, 2006, 05:31 PM
Registered User
 
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jim!

Could you explain a bit how you would use a GridView to insert/update data in multiple tables?


Cheers!

JF





Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting Data into Multiple Tables bfoley SQL Server ASP 1 January 3rd, 2008 12:28 AM
Inserting data in multiple tables rohits PHP How-To 1 August 29th, 2006 11:32 PM
Inserting data into 2 tables chrscote Access ASP 1 August 1st, 2005 09:01 AM
Importing Multiple files in Multiple tables Versi Suomi Access 6 June 1st, 2005 08:47 AM
inserting into multiple tables cridley SQL Server 2000 1 January 25th, 2005 12:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.