|
 |
asp_databases thread: Using array to create Update Statement
Message #1 by imran.saleem@b... on Thu, 29 Nov 2001 11:08:28
|
|
Hi,
i have a problem thats beginning to bug me, i have 2 arrays one
containing the fields of table to update and the other containing the
values to update by. This is how far i have got attempting to generate my
Update statement using the values from the first array.
UPDATE NewRecord SET Title = '' AND Forename = '' AND Surname = '' AND
Initials = '' AND alpha_tag = '' AND rusrn = '' AND service = '' AND
organisation = '' WHERE
However i cannot seem to use the other array to insert the values in to
the apropriate part of the statement. Can somebody please suggest a
solution. Here is my code.
FUNCTION updateresults()
Dim strSQLUpdate
FOR EACH obj IN request.form
xFormValues = request.form(obj)
NEXT
xFormArray = array(xFormValues)
form_elem = SPLIT(xFormArray(0),",")
FOR y=0 TO UBOUND(form_elem)
response.write form_elem(y) & "<BR>"
NEXT
strSQLUpdate = "UPDATE "
xlen=UBOUND(maparray)
FOR i=0 TO xlen
xtype=UCASE(maparray(i,0))
IF xtype = "TABLE" THEN
strSQLUpdate = strSQLUpdate & TRIM(maparray(i,1))
& " SET "
xret_fields_arr=SPLIT(maparray(i,2),"|")
xret_no=UBOUND(xret_fields_arr)
FOR j=0 TO xret_no
IF j<xret_no THEN
strSQLUpdate = strSQLUpdate & TRIM
(xret_fields_arr(j)) & " = '' AND "
ELSE
strSQLUpdate = strSQLUpdate & TRIM
(xret_fields_arr(j)) & " = '' "
END IF
NEXT
END IF
NEXT
strSQLUpdate = strSQLUpdate & " WHERE "
response.write strSQLUpdate
END FUNCTION
Message #2 by Kyle Burns <kburns@c...> on Fri, 30 Nov 2001 10:53:07 -0500
|
|
Start by making sure that you are using Option Explicit. Scanning your
code, I see several items that are not declared within the function
(global?). The one that really jumps out is maparray.
Are you using Option Explicit? If not, add Option Explicit and let us know
the result.
=================================
Kyle M. Burns, MCSD, MCT
ECommerce Technology Manager
Centra Credit Union
kburns@c...
-----Original Message-----
From: imran.saleem@b... [mailto:imran.saleem@b...]
Sent: Thursday, November 29, 2001 6:08 AM
To: ASP Databases
Subject: [asp_databases] Using array to create Update Statement
Hi,
i have a problem thats beginning to bug me, i have 2 arrays one
containing the fields of table to update and the other containing the
values to update by. This is how far i have got attempting to generate my
Update statement using the values from the first array.
UPDATE NewRecord SET Title = '' AND Forename = '' AND Surname = '' AND
Initials = '' AND alpha_tag = '' AND rusrn = '' AND service = '' AND
organisation = '' WHERE
However i cannot seem to use the other array to insert the values in to
the apropriate part of the statement. Can somebody please suggest a
solution. Here is my code.
FUNCTION updateresults()
Dim strSQLUpdate
FOR EACH obj IN request.form
xFormValues = request.form(obj)
NEXT
xFormArray = array(xFormValues)
form_elem = SPLIT(xFormArray(0),",")
FOR y=0 TO UBOUND(form_elem)
response.write form_elem(y) & "<BR>"
NEXT
strSQLUpdate = "UPDATE "
xlen=UBOUND(maparray)
FOR i=0 TO xlen
xtype=UCASE(maparray(i,0))
IF xtype = "TABLE" THEN
strSQLUpdate = strSQLUpdate & TRIM(maparray(i,1))
& " SET "
xret_fields_arr=SPLIT(maparray(i,2),"|")
xret_no=UBOUND(xret_fields_arr)
FOR j=0 TO xret_no
IF j<xret_no THEN
strSQLUpdate = strSQLUpdate & TRIM
(xret_fields_arr(j)) & " = '' AND "
ELSE
strSQLUpdate = strSQLUpdate & TRIM
(xret_fields_arr(j)) & " = '' "
END IF
NEXT
END IF
NEXT
strSQLUpdate = strSQLUpdate & " WHERE "
response.write strSQLUpdate
END FUNCTION
$subst('Email.Unsub')
Read the future with ebooks at B&N
http://service.bfast.com/bfast/click?bfmid=2181&sourceid=38934667&categoryid
=rn_ebooks
|
|
 |