|
 |
asp_databases thread: [asp_databases]asp form that collects data to add and update 2 tables
Message #1 by "peter.ntlworld" <peter.bender@n...> on Wed, 12 Dec 2001 18:23:22 -0000
|
|
Sorry if this is simple, but I'm new to this.
I have an asp form that collects data to add and update 2 tables in an
Access 2000 database.
table1.field1 is an auto generated number that acts as the primarykey (user
no.), the
rest of fields in table1 is user info.
table2 contains other related info. on the user, including the foreign key
which is the user no.
Would appreciate help with writing code that distributes the data to the
respective tables, including submitting the primary key to table1 and the
foreign key field to table2.
Any assistance would be much appreciated
Regards
Peter Bender
Message #2 by David Cameron <dcameron@i...> on Thu, 13 Dec 2001 09:02:02 +1100
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C18358.A18CD3AA
Content-Type: text/plain;
charset="windows-1252"
Basic process is insert the information into the user table, get the userid,
insert into the child table.
There link below shows the best way to get the autonumber for Access:
http://www.adopenstatic.com/experiments/fastestautonumber.asp
using that:
Code assumes connection opened, ado constants defined (adovbs.inc) and all
variables declared earlier in the code.
<%
strSQL = "INSERT INTO tblUsers (Field2, Field3) VALUES " &
"('" & Request.Form("Field2") & "', '" & Request.Form("Field2") &
"')"
cn.Execute strSQL, , adCmdText + adExecuteNoRecords
Set rsUser = Server.CreateObject("ADODB.Recordset")
rsUser.Open "SELECT @@IDENTITY", cn, adOpenForwardOnly, adLockReadOnly,
adCmdText
intUserID = rsUser.Fields.Item(0).value
rsUser.Open
Set rsUser = Nothing
stSQL = "INSERT INTO tblUserChild (Field3, UserField1) VALUES " &
"('" & Request.Form("Field3") & "', " & intUserID & ")"
cn.Execute strSQL, , adCmdText + adExecuteNoRecords
%>
You will need to change this as fits your code, but you get the idea.
regards
David Cameron
nOw.b2b
dcameron@i...
-----Original Message-----
From: peter.ntlworld [mailto:peter.bender@n...]
Sent: Thursday, 13 December 2001 4:23 AM
To: ASP Databases
Subject: [asp_databases] [asp_databases]asp form that collects data to
add and update 2 tables
Sorry if this is simple, but I'm new to this.
I have an asp form that collects data to add and update 2 tables in an
Access 2000 database.
table1.field1 is an auto generated number that acts as the primarykey (user
no.), the
rest of fields in table1 is user info.
table2 contains other related info. on the user, including the foreign key
which is the user no.
Would appreciate help with writing code that distributes the data to the
respective tables, including submitting the primary key to table1 and the
foreign key field to table2.
Any assistance would be much appreciated
Regards
Peter Bender
$subst('Email.Unsub').
|
|
 |