Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modifying a dynamic recordset.

Status
Not open for further replies.

JohannIcon

Programmer
Sep 3, 2002
440
MT
Hi All,

I have a table which is displaying a list of dynamic records, and at the end of the form, I have a button to modify these records. What I wish to do is allow the user to modify any record he wants to and then when he presses the Modify button, the UPDATE clause updates all the recordset with the new values. I have tried very hard to come to a solution but I did not manage. Can you please help me out here?

Thanks very much for your help and time!
 
ASP does not work well with multiple records, but here is a suggestion. When the page is loading with your dinamic records, uniquely identify each text of each record using a loop. When the user updates the records, resave each text field in each record using again a loop. Use a hidden field if you need to hide the record key(s).

I hope this helps.

Denis
 
Yeah I tried that but I did not manage to do it. I saved the tableID in a hidden field, but then when I came to update the table, I could not look these hidden fields
 
Rather than saving the tableID in a field, try something like this:
Code:
<%
'we have a recordset called rs, with fields tableID, fave_color, comments
%>
<form method=&quot;POST&quot; action=&quot;secondpage.asp&quot; name=&quot;frmUpdate&quot;>
<%
rs.MoveFirst
Do Until rs.EOF
   Response.Write &quot;Color: <input type='text' name='color_&quot;&rs(&quot;tableId&quot;)&&quot;' value='&quot; & rs(&quot;fave_color&quot;) & &quot;' onChange='frmUpdate.&quot; & rs(&quot;tableId&quot;) & &quot;_action.value=&quot;&quot;update&quot;&quot;'>&quot;
   Response.Write &quot;Comments: <input type='text' name='comments_&quot;&rs(&quot;tableId&quot;) & &quot;' value='&quot; & rs(&quot;comments&quot;) & &quot;'onChange='frmUpdate.&quot; & rs(&quot;tableId&quot;) & &quot;_action.value=&quot;&quot;update&quot;&quot;'>&quot;
   Response.Write &quot;<input type='text' name='action_&quot; & rs(&quot;tableId&quot;) & &quot;' value=''><br>&quot;
   rs.MoveNext
Loop
%>
Ok so this should spit out two text inputs and a hidden field. For a recordset that looks like this:
Code:
tableId   fave_color   comments
1         red          i like red
2         blue         i like clouds
3         black        need more coffee
The HTML output of the page will look like this:
Code:
Color: <input type='text' name='color_1' value='red' onClick='frmUpdate.action_1.value=&quot;update&quot;>
Comments: <input type='text' name='comments_1' value='i like red' onClick='frmUpdate.action_1.value=&quot;update&quot;>
<input type='hidden' name='action_1' value=''><br>

Color: <input type='text' name='color_2' value='blue' onClick='frmUpdate.action_2.value=&quot;update&quot;>
Comments: <input type='text' name='comments_2' value='i like clouds' onClick='frmUpdate.action_2.value=&quot;update&quot;>
<input type='hidden' name='action_2' value=''><br>

Color: <input type='text' name='color_3' value='black' onClick='frmUpdate.action_3.value=&quot;update&quot;>
Comments: <input type='text' name='comments_3' value='need more coffee' onClick='frmUpdate.action_3.value=&quot;update&quot;>
<input type='hidden' name='action_3' value=''><br>

So in order to parse this on your update page all you would need to do is:
Code:
Dim itm
Dim tColor, tComments, tId
For each itm in Request.Form
   If InStr(itm.key,&quot;action&quot;) AND itm.value <> &quot;&quot; Then
      tId = right(itm.key,len(itm.key)-7)  'get rid of the action_
      tColor = Request.Form(&quot;color_&quot;&tId)
      tComments = Request.Form(&quot;comments_&quot;&tId)

      'update your db record here
   End If
Next


There are several other ways to do this as well, you can take a look at the FAQ I wrote from the FAQs link above where I have another example of updating multiple rows at once.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top