JustAsking
08-27-2004, 02:18 AM
I am reading in a group of results from a user form when the form is submitted. The purpose of the code is to split the group of results into single records and then update the records in a SQL server database. Most of the code appears to work but the when looking at the sql statement produced it is only updating one record from the group of results.
This is the code that I am using in the web page:
Variable 'school' is the group of results from the user form.
Dim schoolEntry, schoolvalues, singlevalues, basic, sql, i, numupdated
schoolEntry=split(school,"*")
'for error checking only
response.write (school&"<br>")
for each schoolvalues in schoolEntry
schoolvalues=replace(schoolvalues,", ",",")
basic=split(schoolvalues,",")
'for error checking only
response.write schoolvalues
next
for each singlevalues in basic
sql="UPDATE sss_results SET "
i=1
do while i >= 0
select case i
case 0
sql=sql & "WHERE school_name=" & SQLFormat(basic(i)) & ""
case 1
sql=sql & "save_priority=" & basic(i) & " "
end select
i = i - 1
loop
'for error checking only
response.write ("<br>"&sql)
conn.Execute sql
next
This is what is displayed with response.write (school&"<br>"):
*Biggenden State School, 1, *Mungar State School, 2
This is what is displayed with response.write schoolvalues:
Biggenden State School,1,Mungar State School,2
This is the result of the sql statement, but it is only 'reading' one record of the array:
UPDATE sss_results SET save_priority=2 WHERE school_name=Mungar State School
UPDATE sss_results SET save_priority=2 WHERE school_name=Mungar State School
I thought the result of the sql statement should be something like this:
UPDATE sss_results SET save_priority=2 WHERE school_name=Mungar State School
UPDATE sss_results SET save_priority=1 WHERE school_name=Biggenden State School
I have looked at this from every side and cannot see what part of the code is causing the problem.
Any help is greatly appreciated.
This is the code that I am using in the web page:
Variable 'school' is the group of results from the user form.
Dim schoolEntry, schoolvalues, singlevalues, basic, sql, i, numupdated
schoolEntry=split(school,"*")
'for error checking only
response.write (school&"<br>")
for each schoolvalues in schoolEntry
schoolvalues=replace(schoolvalues,", ",",")
basic=split(schoolvalues,",")
'for error checking only
response.write schoolvalues
next
for each singlevalues in basic
sql="UPDATE sss_results SET "
i=1
do while i >= 0
select case i
case 0
sql=sql & "WHERE school_name=" & SQLFormat(basic(i)) & ""
case 1
sql=sql & "save_priority=" & basic(i) & " "
end select
i = i - 1
loop
'for error checking only
response.write ("<br>"&sql)
conn.Execute sql
next
This is what is displayed with response.write (school&"<br>"):
*Biggenden State School, 1, *Mungar State School, 2
This is what is displayed with response.write schoolvalues:
Biggenden State School,1,Mungar State School,2
This is the result of the sql statement, but it is only 'reading' one record of the array:
UPDATE sss_results SET save_priority=2 WHERE school_name=Mungar State School
UPDATE sss_results SET save_priority=2 WHERE school_name=Mungar State School
I thought the result of the sql statement should be something like this:
UPDATE sss_results SET save_priority=2 WHERE school_name=Mungar State School
UPDATE sss_results SET save_priority=1 WHERE school_name=Biggenden State School
I have looked at this from every side and cannot see what part of the code is causing the problem.
Any help is greatly appreciated.