Forums

This topic is locked

Multiple Record Insertion

Posted 07 Jul 2005 10:11:03
1
has voted
07 Jul 2005 10:11:03 Chris Trace posted:
Hey all,

I am trying to insert 12 fields from one form into 12 different tables of the one database.

Can anyone give me an idea on how this is done.

Thanks

Replies

Replied 08 Jul 2005 21:45:19
08 Jul 2005 21:45:19 Simon Martin replied:
With dificulty!
If all you want to do is simply insert the values then you could consider hand coding your INSERT but if you want to record parent-child relationships then it gets a bit trickier... If you're lucky and you've got something like SQL server then you could write a Stored Procedure to INSERT your parent data and then use @@IDENTITY (or @@SCOPE_IDENTITY - but I've only just discovered this 2nd option) to return the ID of the record you've just inserted. Then you can use that variable when inserting your child data.

There is a useful extension InsertRecordWithIdent by Gerorge Petrov that does something similar; it gets the @@IDENTITY value and passes it back to the browser which then needs to compose the 2nd phase of the insert. Less programming for you but slower overall and less control over how your data is handled.

HTH

Live the life you love
Love the life you live
~ ~ ~ ~ ~ ~ ~
<b>Simon Martin</b> - <i>DMXzone Manager</i>
<font size=1>[ Dreamweaver MX/MX2004 | ASP | SQL | XHTML/CSS | Web Accessibility ] </font id=size1>
Replied 09 Jul 2005 01:37:52
09 Jul 2005 01:37:52 paul durbar replied:
As Simon says, the best solution here is a stored proc but if you're just looking for a quick fix and something that'd work then just use something like:

Set MultiRecordAdd = Server.CreateObject("ADODB.Recordset"
MultiRecordAdd.ActiveConnection = MyConnString
MultiRecordAdd.Source = "SELECT * FROM MyFirstTable"
MultiRecordAdd.CursorType = 0
MultiRecordAdd.CursorLocation = 2
MultiRecordAdd.LockType = 3
MultiRecordAdd.Open
MultiRecordAdd.Addnew
MultiRecordAdd("somecolumnname" = Request.Form("someformvariable"
MultiRecordAdd.update
MultiRecordAdd.Close()
' insert record in 2nd table
MultiRecordAdd.Source = "SELECT * FROM MySecondTable"
MultiRecordAdd.Open
MultiRecordAdd.Addnew
MultiRecordAdd("somecolumnname" = Request.Form("someformvariable"
MultiRecordAdd.update
MultiRecordAdd.Close()
' insert record in 3rd table
MultiRecordAdd.Source = "SELECT * FROM MyThirdTable"
MultiRecordAdd.Open
MultiRecordAdd.Addnew
MultiRecordAdd("somecolumnname" = Request.Form("someformvariable"
MultiRecordAdd.update
MultiRecordAdd.Close()

etc

etc

Set MultiRecordAdd = Nothing

Hope that helps, its a workaround but it'd do the job









D2 Sitelock v3.0
Sell and securely deliver downloads, paid subscription systems and website membership areas:
www.d2computing.co.uk/sitelock.htm

Edited by - durbs on 09 Jul 2005 01:39:14

Reply to this topic