Print Page | Close Window

Updating 2 SQL tables using ASP

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=3965
Printed Date: 30 March 2026 at 10:06am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Updating 2 SQL tables using ASP
Posted By: Awangku
Subject: Updating 2 SQL tables using ASP
Date Posted: 30 June 2003 at 7:46pm

What is wrong with this code? The first part with tblTest1 is okay. No problem there. But when it comes to updating tblTest2, I got that "HTTP 500 - Internal server error" message. What did I do wrong?

strInput1 = Trim(Request.Form("Input1"))
strInput2 = Trim(Request.Form("Input2"))

strCon = <..some connection..>
strSQL = "SELECT * FROM tblTest1;"

Set rsProcessInput = Server.CreateObject("ADODB.Recordset")

rsProcessInput.CursorType = 2
rsProcessInput.LockType = 3

rsProcessInput.Open strSQL, strCon

rsProcessInput.AddNew

rsProcessInput.Fields("Input1").value = strInput1
rsProcessInput.Fields("Input2").value = strInput2

rsProcessInput.Update
rsProcessInput.Requery
rsProcessInput.MoveLast

rsProcessInput.Close
Set rsProcessInput = Nothing

'update tblTest2 if strInput1 = A

If strInput1 = "A" Then

     Dim rsUpdateTest2

     Set rsUpdateTest2 = Server.CreateObject("ADODB.Recordset")

     strSQL = "SELECT * FROM tblTest2;"

     rsUpdateTest2.Open strSQL, strCon

     rsUpdateTest2.CursorType = 2
     rsUpdateTest2.LockType = 3

     rsUpdateTest2.Fields("Input1").value = strInput1
     rsUpdateTest2.Fields("Input2").value = strInput2

     rsUpdateTest2.Update
     rsUpdateTest2.Requery
     rsUpdateTest2.MoveLast

     rsUpdateTest2.Close
     Set rsUpdateTest2 = Nothing

End If

Set strCon = Nothing




Replies:
Posted By: ljamal
Date Posted: 30 June 2003 at 8:40pm
Why not use:

strSQL = "insert into tblTest1 (Input1, Input2) values ('"&strInput1&"', '"&strInput2&"')"

strCon.Open
strCon.Execute (strSQL)

If strInput1 = "A" Then
   strSQL = "insert into tblTest2 (Input1, Input2) values ('"&strInput1&"', '"&strInput2&"')"
   strCon.Open
   strCon.Execute (strSQL)
End If

If you are using SQL Server then I would suggest:

strSQL = "insert into tblTest1 (Input1, Input2) values ('"&strInput1&"', '"&strInput2&"');"

If strInput1 = "A" Then
   strSQL = strSQL & "insert into tblTest2 (Input1, Input2) values ('"&strInput1&"', '"&strInput2&"')"
End If

strCon.Open
strCon.Execute (strSQL)

There is no need to open a recordset to do an insert or an update.


-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net