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

Multiple Table Insert

Status
Not open for further replies.
Jan 19, 2003
34
US
If I use the record insertion live object, it only lets me input data for one table at a time. Is it possible to have data fields from multiple tables on the same insertion page?
 
[tt]

Here's how to insert into two separtate tables using .ASP

*********************************************************

<form name=&quot;Search&quot; method=&quot;Post&quot; action=&quot;addtodatabase.asp&quot;>
'addtodatabase.asp is the page that connects to the database.
FirstName <input type=&quot;text&quot; name=&quot;txtFirstName&quot; size=&quot;20&quot;>
LastName <input type=&quot;text&quot; name=&quot;txtLastName&quot; size=&quot;20&quot;>
UserName <input type=&quot;text&quot; name=&quot;txtUserName&quot; size=&quot;20&quot;>
Password <input type=&quot;text&quot; name=&quot;txtPassword&quot; size=&quot;20&quot;>
<input type=&quot;submit&quot; name=&quot;btnSearch&quot; value=&quot;Add&quot;>
</form>

'Save this page as addRec.asp
'-----------------------------------------------------------------------------


'Now create your addtodatabase.asp page. (note the action method in the above
'form).

'put the below 3 lines at the top of the page above all HTML tags.


<%@ Language=VBScript %>
<% Option Explicit %>
<!--#INCLUDE VIRTUAL=&quot;adovbs.inc&quot; -->

'you will need to include the adovbs.inc . If you don't have it then you can
'do a search on it at and you can download the file from there.
'If you get an error that the adovbs.inc file couldn't be found make sure you
'have the correct path or use FILE instead of VIRTUAL.

<%
Dim MyConn, RS, RS2, strFirstName, strLastName, strUserName, strPassword

'grab the form contents
strFirstName = Request.Form(&quot;txtFirstName&quot;)
strLastName = Request.Form(&quot;txtLastName&quot;)
strUserName = Request.Form(&quot;txtUserName&quot;)
strPassword = Request.Form(&quot;txtPassword&quot;)

Set MyConn=Server.CreateObject(&quot;ADODB.Connection&quot;)
Set RS=Server.CreateObject(&quot;ADODB.RecordSet&quot;)

'since you are working with the RecordSet you need to create an instance of
'the RecordSet Object

Set RS2=Server.CreateObject(&quot;ADODB.RecordSet&quot;)
'in this case, since we're adding to two separate tables we need to create
'two instances of the RecordSet Object

MyConn.Open &quot;getdata&quot;
'getdata is your DSN (data source name) you created through ODBC
RS.Open &quot;Select * From tblCustomer&quot;, MyConn, adOpenDynamic, adLockPessimistic, adCMDText
RS2.Open &quot;Select * From tblUser&quot;, MyConn, adOpenDynamic, adLockPessimistic, adCMDText
'open both RecordSets

RS.AddNew
RS(&quot;FirstName&quot;)= strFirstName
RS(&quot;LastName&quot;)= strLastName
RS.Update
'Update the first RecordSet

RS2.AddNew
RS2(&quot;UserName&quot;)= strUserName
RS2(&quot;Password&quot;)= strPassword
RS2.Update
'Update the second RecordSet

'Clean up

RS.Close
RS2.Close
MyConn.Close
Set RS = Nothing
Set RS2 = Nothing
Set MyConn = Nothing
%>

'That's it!

*********************************************************

<%=Tony%>
€ € € € € € € € € €
 
Thanks Tony! That was pretty comprehensive. I really appreciate it. I've been learning ASP and VBScript lately so I can customize my pages(application) created in ultradev, but I obviously haven't gotten very far. You saved me alot of time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top