loop update statement in classic asp

2019-08-28 17:41发布

问题:

I really need some help with this code. The loop is only making the update statement run once when there are maybe 4 records chosen so it has to loop 4 times. This is the 1st time ive come across this problem and I cant seem to see why it is doing it like that. Please help. Thank you.

<!--#include file="connectionString.inc"-->
<%
Dim strmode, arrmode,i,rs,SQLstr, a, b, site_to


strmode=Request.form("changeBox")
cont1=request.form("cont1")
arrmode=split(strmode,",")




if request.form("submitChange") = "" then
    response.write("Please try again, you have no selected anything. Press back on your browser")
end if
   if request.form("submitChange") = "site" then
    response.write(b)
    for i = 0 to UBound(arrmode)
        SQLstr = "UPDATE SCSer SET Ser_Site_Num = '" & request.form("site_to") & "' WHERE Ser_Num = '" & arrmode(i) & "'"
        Set rs = Server.CreateObject("ADODB.Recordset")
        rs.open SQLstr, conn, 1, 2       
        Response.Write("SUCCESSFULLY UPDATED! " + arrmode(i))
    next
end if

if request.form("submitChange") = "contract" then
    a=LBound(arrmode)
b=UBound(arrmode)
    SQLstr = "UPDATE SCSer SET Ser_Site_Num = '" & request.form("site_to") & "' WHERE Ser_Num BETWEEN '" & arrmode(a) & "' AND '" & arrmode(b) & "'"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.open SQLstr, conn, 1, 2
    Response.Write("SUCCESSFULLY UPDATED! <br/>")
    response.write(arrmode(a)+"<br/>")
    response.write(arrmode(b))
end if
%>

回答1:

Try this and see what the response says:

<%
Dim strmode, arrmode,i,rs,SQLstr, a, b, site_to
Dim oConn

strmode=Request.form("changeBox")
cont1=request.form("cont1")
arrmode=split(strmode,",")

Response.Write "submitChange is:" & request.form("submitChange") & "<br>"


if request.form("submitChange") = "" then
    response.write("Please try again, you have not selected anything. Press back on your browser")
    Response.end
end if

set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open conn

if request.form("submitChange") = "site" then
    for i = 0 to UBound(arrmode)
        SQLstr = "UPDATE SCSer SET Ser_Site_Num = '" & request.form("site_to") & "' WHERE Ser_Num = '" & Trim(arrmode(i)) & "'"
        Response.Write "Executing SQL: "& SQLstr &"<br>"
        oConn.Execute(SQLstr)      
        Response.Write("SUCCESSFULLY UPDATED! " + arrmode(i))
    next
end if

if request.form("submitChange") = "contract" then
    a=LBound(arrmode)
    b=UBound(arrmode)
    SQLstr = "UPDATE SCSer SET Ser_Site_Num = '" & request.form("site_to") & "' WHERE convert(int,Ser_Num) BETWEEN " & arrmode(a) & " AND " & arrmode(b) & ""
    Response.Write "Executing SQL: "& SQLstr &"<br>"
    oConn.Execute(SQLstr)    
    Response.Write("SUCCESSFULLY UPDATED! <br/>")
    response.write(arrmode(a)+"<br/>")
    response.write(arrmode(b))
end if
%>