|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have 2 tables in a database. One called "View" and one called "Main". These aren't linked for various reasons, though they can be linked if it will solve me problem.
I am trying to insert values into both view and main. (These being part of a logging in and storing details system) The code is as follows Code:
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Mode=adModeReadWrite
conn.Open "htdocs\ADO\database.mdb"
sql="INSERT INTO Main Values"
sql=sql & "('" & Request.Form("Username") & "',"
sql=sql & "'" & Request.Form("Password") & "',"
sql=sql & "'Basic',"
sql=sql & "'" & Request.Form("Firstname") & "',"
sql=sql & "'" & Request.Form("Lastname") & "',"
sql=sql & "'" & Request.Form("Country") & "',"
sql=sql & "'" & Request.Form("Email") & "')"
sql=sql & " AND "
sql=sql & "INSERT INTO View Values"
sql=sql & "('" & Request.Form("Username") & "',"
sql=sql & "'#c0d9e9',"
sql=sql & "'#e2f2fb',"
sql=sql & "'#a0d4f2',"
sql=sql & "'#e2f2fb',"
sql=sql & "'#a0d4f2',"
sql=sql & "'#ffffff')"
on error resume next
conn.Execute sql
if err<>0 then
for each Err in Conn.Errors
response.write("<p>")
response.write("Description: ")
response.write(Err.Description & "<br />")
response.write("Help context: ")
response.write(Err.HelpContext & "<br />")
response.write("Help file: ")
response.write(Err.HelpFile & "<br />")
response.write("Native error: ")
response.write(Err.NativeError & "<br />")
response.write("Error number: ")
response.write(Err.Number & "<br />")
response.write("Error source: ")
response.write(Err.Source & "<br />")
response.write("SQL state: ")
response.write(Err.SQLState & "<br />")
response.write("</p>")
next
Response.Write("<h3>Error</h3><P>")
Response.Write("An error occured while trying to register you! Please contact the
site administrator for further support.")
else
Response.Write("<h3>You have successfully been register</h3>")
Repsonse.Write("An email has been sent to you to keep as a record of your user
details. Please keep this email private and in a safe place. Click HERE to login!")
end if
conn.close
I have tried doing the 2 inserts seperately; executing one then compiling th eother into the variable then executing that one. but it still gives me the same error stating "Illegal Assignment". The database is not read only, have complete access to it and performing just the one insert (Main) works, but not with the second. Any help appreciated Thanks |
|
#2
|
|||
|
|||
|
instead of this u can write both the Insert statements within a transaction in a stored procedure.
Sony |
|
#3
|
||||
|
||||
|
Hi,
i see you are using an access database, try using a ; instead of 'and' Code:
sql="INSERT INTO Main Values"
sql=sql & "('" & Request.Form("Username") & "',"
sql=sql & "'" & Request.Form("Password") & "',"
sql=sql & "'Basic',"
sql=sql & "'" & Request.Form("Firstname") & "',"
sql=sql & "'" & Request.Form("Lastname") & "',"
sql=sql & "'" & Request.Form("Country") & "',"
sql=sql & "'" & Request.Form("Email") & "')"
sql=sql & ";"
sql=sql & "INSERT INTO View Values"
sql=sql & "('" & Request.Form("Username") & "',"
sql=sql & "'#c0d9e9',"
sql=sql & "'#e2f2fb',"
sql=sql & "'#a0d4f2',"
sql=sql & "'#e2f2fb',"
sql=sql & "'#a0d4f2',"
sql=sql & "'#ffffff')"
hope this helps
__________________
Look! Its a ShemZilla ![]() ![]()
|
|
#4
|
|||
|
|||
|
I see your using SQL, how about using a trigger in that table to insert value into other table??
|
|
#5
|
|||
|
|||
|
I see your using SQL, how about using a trigger in table MAIN to insert value into table VIEW whenever the record is inserted on that table??
|
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > Insert Into more than one table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|