Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2004
    Posts
    10

    Unanswered: Multiple Updates

    I have a app I am working on that allows the user to input manually a number to a txtbox. But the number of text boxes will change depending on the number of records for that user. I want to take all the numbers they enter for every record and put that value into the right spot.

    Basicly I get a bunch of records and each record has a text box at the end of it to put a number


    <form action="postdb.asp">
    Loop
    <input type=text size=2 value=<%Response.Write rsViewEvents("ordernum")%>>
    End Loop
    <input type=submit value='update order'>
    </form>


    So they enter their numbers and basicly I want to update all the records with this number. How can I do this so they get into the correct location?

    Thanks
    --Todd

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Easiest way is to suffix the name of the text box at the end of the row with an identifier that show what record the value in the box is for eg.
    Code:
    <form action="postdb.asp">
    Loop
    <input type=text size=2 name="update<%=rsViewEvents("id")%>" value=<%Response.Write rsViewEvents("ordernum")%>>
    End Loop
    <input type=submit value='update order'>
    </form>
    then you can loop though requesting the fields and if there is a value update eg.
    Code:
    for i = startId to endID
       myvalue = request("update" & i)
       if myvalue<>"" then updateRecord(i, myvalue)
    next

  3. #3
    Join Date
    Jan 2004
    Posts
    10
    Should this do it you think?

    startID = 1
    strSQL = "Select Count(*) AS endID FROM test"
    adoCon.Execute strSQL

    for i = startID to endID
    txtOrderValue = request("txtOrder_" & i)
    if txtOrderValue <> then
    strSQLUpdate = "UPDATE test SET ordernum = & txtOrderValue & WHERE ID =" & i
    adoCon.Execute strSQLUpdate
    end if
    next

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    bascially,.. assuming your id's are all in sequence... but you will probably find that they won't be in sequence...

    so you will have to loop through your request object, find all the objects whose name starts with update. slice the id off the end of the name and then do your update...

    something more like...

    Code:
    for each item in Request
      if left(item.key,6 = "txtOrder_") then
        myId = mid(item.key,10)
        txtOrderValue = request("txtOrder_" & myId)
        if txtOrderValue <> "" then
          strSQLUpdate = "UPDATE test SET ordernum = & txtOrderValue & WHERE ID =" & myId
          adoCon.Execute strSQLUpdate
        end if
      end if
    next

  5. #5
    Join Date
    Jan 2004
    Posts
    10
    Like this? Sorry I am new to this

    startID = 1
    strSQL = "Select Count(*) AS endID FROM test"
    adoCon.Execute strSQL

    for each item in Request
    if left(item.key,6 = "txtOrder_") then
    myId = mid(item.key,10)
    txtOrderValue = request("txtOrder_" & myId)
    if txtOrderValue <> "" then
    strSQLUpdate = "UPDATE test SET ordernum = '" & txtOrderValue & "' WHERE ID =" & myId
    adoCon.Execute strSQLUpdate
    end if
    end if
    next

  6. #6
    Join Date
    Jan 2004
    Posts
    10
    With this code I get this error when I hit the submit buttong

    Microsoft VBScript runtime error '800a01b6'

    Object doesn't support this property or method

    /est/test.asp, line 13


    line 13 is this

    for each item in Request

  7. #7
    Join Date
    Jan 2004
    Posts
    10
    here is all my code for the page



    <!--#include file='dbconnection.inc'-->

    <%



    If Request.querystring("mode") = "db" then

    startID = 1
    strSQL = "Select Count(*) AS endID FROM test"
    adoCon.Execute strSQL

    for each item in Request
    if left(item.key,6 = "txtOrder_") then
    myId = mid(item.key,10)
    txtOrderValue = request("txtOrder_" & myId)
    if txtOrderValue <> "" then
    strSQLUpdate = "UPDATE test SET ordernum = '" & txtOrderValue & "' WHERE ID =" & myId
    adoCon.Execute strSQLUpdate
    end if
    end if
    next


    End If







    Set rsEventsAdmin = Server.CreateObject("ADODB.Recordset")

    strSQL = "SELECT ID, text, ordernum FROM test"

    rsEventsAdmin.Open strSQL, adoCon


    Response.Write ("<table><tr><td>ID</td><td>Text</td><td>Order</td></tr><form method='post' action='test.asp?mode=db'")

    Do While NOT rsEventsAdmin.EOF
    Response.Write ("<tr><td>")
    Response.Write (rsEventsAdmin("ID"))
    Response.Write ("</td>")
    Response.Write ("<td>")
    Response.Write (rsEventsAdmin("text"))
    Response.Write ("</td><td><input type='text' name='txtOrder_")
    Response.Write (rsEventsAdmin("ID"))
    Response.Write ("' size='2'value=")
    Response.Write (rsEventsAdmin("ordernum"))
    Response.Write ("></td>")
    Response.Write ("</tr>")
    rsEventsAdmin.MoveNext
    Loop


    Response.Write ("<input type=submit value=submit></form></table>")

    Set rsEventsAdmin = Nothing
    Set adoCon = Nothing


    %>

  8. #8
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Like I said it was something "like" what a gave you not actually what I gave you... it's more something like

    For Each strKey In Request.Form
    If Request.Form(strKey) then
    End If
    Next

    I advise reading a little on the msdn site....

    http://msdn.microsoft.com/library/de..._vbom_reqo.asp

    http://msdn.microsoft.com/library/de...bom_reqocf.asp

    http://msdn.microsoft.com/library/de...eqoccookie.asp

    which should help you met your end goal.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •