If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Multiple Updates

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-04, 20:37
twooly twooly is offline
Registered User
 
Join Date: Jan 2004
Posts: 10
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
Reply With Quote
  #2 (permalink)  
Old 03-01-04, 20:46
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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
Reply With Quote
  #3 (permalink)  
Old 03-01-04, 21:13
twooly twooly is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 03-01-04, 21:33
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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
Reply With Quote
  #5 (permalink)  
Old 03-01-04, 21:43
twooly twooly is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 03-01-04, 21:48
twooly twooly is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 03-01-04, 21:51
twooly twooly is offline
Registered User
 
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


%>
Reply With Quote
  #8 (permalink)  
Old 03-01-04, 23:03
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On