Forums

This topic is locked

Multiple Inserts per Page

Posted 06 Dec 2002 21:36:43
1
has voted
06 Dec 2002 21:36:43 A. B. posted:
I'm trying to add a new record which will insert information into two different tables in the same SQL 7 db. UD 4 only allows one insert per page. How do people get around this?

Thank you in advance.

Andrea

Replies

Replied 08 Dec 2002 23:21:08
08 Dec 2002 23:21:08 David Behan replied:
As far as I know, you have to get into the source code for this one. I remember Dreamweaver restricts putting more than one update, insert, or delete on the one page. To get around this I started hand coding and now I don't even use DW code, just my own collection of functions and snippets. If you haven't hand coded before, this might be a good opportunity to start. You obviously want more from DW than it has to offer.

Couple of ways to do it:

1. Delete the line for Response.Redirect after the DW created code for the insert. In its place, put in some code to do the second insert and then do the redirect.

2. Don't use the dreamweaver created insert code. Do the insert something like this:


'**************************************************************
'You can put the database connection and function into an include file
'and then pull them into each page you require them in.


'DSN-Less Connection String
'Dim dbase_source
'dbase_source = "dsn=dsnname;pwd=temp;"

'Cursor Type
cursor_type = 3

'Function for inserting into database
FUNCTION InsertRecord(insert_name,sql_text)

SET insert_name = Server.CreateObject("ADODB.Command"
insert_name.ActiveConnection = dbase_source
insert_name.CommandText = sql_text
insert_name.CommandType = 1
insert_name.CommandTimeout = 0
insert_name.Prepared = true
insert_name.Execute()

END FUNCTION

'Request form variables
strName = Replace(Request.Form("form_name","'","''"
strEmail = Replace(Request.Form("form_email","'","''"
strPhone = Replace(Request.Form("form_phone","'","''"
strCountry = Replace(Request.Form("form_country","'","''"

'Set sql text
sql_text1 = INSERT INTO TBL_USERS1 (USER_NAME,USER_EMAIL) VALUES ('" & strName & "','" & strEmail & "')
sql_text2 = INSERT INTO TBL_USERS2 (USER_PHONE,USER_COUNTRY) VALUES ('" & strPhone & "','" & strCountry & "')

'Do the inserts
CALL InsertRecord(insUserTbl1,sql_text1)
CALL InsertRecord(insUserTbl2,sql_text2)

'Redirect to confirmation page
Response.Redirect("complete.asp"

'**************************************************************

Regards,

David

_________________________
WinXP : IIS 5.1 : StudioMX : ASP : VBScript
www.clicksdesign.com
Replied 09 Dec 2002 12:58:31
09 Dec 2002 12:58:31 Kent Steelman replied:
I am not familar with SQL but the way I handle it is through a querry/view. I create a querry (in Access), and have my form update the querry, the querry in MS Access will update multiple table.

Wm. Kent Steelman
Replied 09 Dec 2002 18:46:24
09 Dec 2002 18:46:24 A. B. replied:
David and Kent,

Thank you SO much for your feedback. I will start to do some hand coding now since UD is quite limited.

David, thanks so much for your detailed example. It has helped me so much!

Andrea

Reply to this topic