Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 29th, 2006, 03:57 AM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple UPDATE will not work

Hi

I have the follwoing code:

<%
If Request.Form("Process")="True" Then

intRecIDs = request("TypeID")
arrRecIDs = Split(intRecIDs, ", ")
For i = 0 to Ubound(arrRecIDs) ' Loop trough the array
strText = request("txtValue")
strNum = request("PlanType")

set commUpdate = Server.CreateObject("ADODB.Command")
commUpdate.ActiveConnection = MM_login_STRING
commUpdate.CommandText = "UPDATE all_customer_apollo SET Total_QTR = " & strText & " AND Rec_Term = " & strNum & " WHERE OrderRef = " & intRecIDs

commUpdate.CommandType = 1
commUpdate.CommandTimeout = 0
commUpdate.Prepared = true
commUpdate.Execute()
Next

End If
%>

Everytime i run the code it comse back with the error:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.

If i run the update on just one file it works fine but when done on multiple records it kicks back the error.

Does anyone have any ideas

Cheers

Simon

 
Old March 30th, 2006, 08:57 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

God do i hate ASP's debugger. Anyway. Your WHERE clause is messed up because, from the way your loop is structure, you are looping based on the upper bound indecy of arrRecIDs but you are not updating based on the current value of the array, you are trying to update based on a single integer (though since you are calling split() on it its really a string) thats where your problem is.

Take this for example

intRecIDs = "1,2,3,4"
arrRecIDs = Split(intRecIDs, ",")

your array looks like this

arrRecIDs(0) = 1
arrRecIDs(1) = 2
arrRecIDs(2) = 3
arrRecIDs(3) = 4

the 2 solutions here are 1) change your where clause to this: WHERE OrderRef = " & arrRecIDs(i) or
2) WHERE OrderRef IN(" & intRecIDs &")"

If you decide with the latter of the 2, drop your for loop. (You wont need to iterate through each RecID because an IN clause works like this: if this column matches any one of these values, UPDATE. )

That should get you going. (And use commas instead of AND when seperating columns, looks more professional ;])

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
update multiple columns in an update statement debbiecoates SQL Server 2000 1 August 17th, 2008 04:01 AM
How does Update Link in FormView work? URGENT shaly ASP.NET 2.0 Professional 0 December 7th, 2006 04:10 PM
update/insert work in queries but not on form jonicholson Access VBA 3 January 18th, 2005 06:05 PM
update query doesnt work knight Classic ASP Databases 4 June 10th, 2004 07:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.