insert into 2 tables, asp and microsoft access (1 Viewer)

dbertanjoli

Registered User.
Local time
Today, 15:42
Joined
Sep 22, 2000
Messages
102
Hello I have problems writing data from my webform to two tables. I am quiet sure that my insert into syntax is not correct. How to insert data into access database into 2 relational tables?
This is my code:
<%
' Declaring variables
Dim name, age, dateDB, QuestionOne, data_source, con, sql_insert

' A Function to check if some field entered by user is empty
Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "''")
End Function

' Receiving values from Form
name = ChkString(Request.Form("name"))
age = ChkString(Request.Form("age"))
dateDB = ChkString(Request.Form("dateDB"))
QuestionOne = ChkString(Request.Form("QuestionOne"))


data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("form.mdb")

sql_insert = "insert into users (name, age, dateDB) values ('" & _ name & "', '" & age & "', '" & dateDB & "'); insert into Diagnosis (QuestionOne) values ('" & _ QuestionOne & "')"


' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")

con.Open data_source
con.Execute sql_insert
' Done. Close the connection
con.Close
Set con = Nothing


Response.Write "All records were successfully entered into the database."
%>
 

Velosai

Registered Headache Cause
Local time
Today, 15:42
Joined
Aug 3, 2007
Messages
38
You will need to do it as two separate SQLs, doing the child table first
 

Users who are viewing this thread

Top Bottom