Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Updating 2 SQL tables using ASP
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Updating 2 SQL tables using ASP

 Post Reply Post Reply
Author
Awangku View Drop Down
Groupie
Groupie


Joined: 15 November 2001
Location: Malaysia
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Awangku Quote  Post ReplyReply Direct Link To This Post Topic: Updating 2 SQL tables using ASP
    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

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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.


Edited by ljamal
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.