Update multiple records using form and ASP?
Hi--
I need to create an administrative interface for a non-technical user to modify numbers in a database. I have created a form that dynamically pulls in the numeric values, but I'm stumped on how to get all the numeric values to update on submit. Since the form fields are dynamically generated, I have left them unnamed. Where can I go from here?
Sarah
<% Dim objRS
if ratetype="1" then
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "SELECT * FROM Rates WHERE rCategoryID =" & ratetype ,_
strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
response.write "<form name = 'updaterates'>"
response.write "<table width='75%' border='0' cellspacing='1' cellpadding='2'>"
response.Write "<tr class='gentext'><td><b>Product</b></td><td><b>Initial Deposit</b></td><td><b>Interest Rate</b></td><td><b>APY</b></td></tr>"
While Not objRS.EOF
response.write "<tr><td><input type='text' value='" & objRS(2) & "'></td>"
response.write "<td><input type='text' value='" & objRS(3) & "'</td>"
response.write "<td><input type='text' value='" & objRS(4) & "'</td>"
response.write "<td><input type='text' value='" & objRS(5) & "'</td></tr>"
objRS.MoveNext
Wend
Response.write "<tr><td colspan='4' class='gentext' align='center'><input type='submit' value='submit'></td></tr></table>"
END IF%>
Comments
Well ...
Hi Sarah. All you really need to do is add a varable or variables that will allow you to be able to name your text boxes, and the update the variable while you move through the record set. So that when you then update the database you can you the same kind of loop to create the info needed to update the database.
Fo example you can create four variables in you case all will a number appened to the end so you will end up with
TextOne1, TextTwo1, Textthree1, TextFour1 .... Then you add one to a counter ( a seperate variable, and then next time in the loop you will have another set of names to use TextOne2, TextTwo2, Textthree2, TextFour2
You now have a way to reference you text boxes and create the SQL string to update you database. You do this in the same way. Make a loop with a counter and increament it then adding the new information to the string each time. If you want a more detailed explaination just reply to this thread and I will help out.
Leith
You must me logged in to write a comment.