Click to See Complete Forum and Search --> : Updating, adding and deleting multiple records at the same time


at51178
08-02-2005, 03:12 PM
Hi

I am currently in the process of building a small website that will store my stock portfollio.

I currently know how to add delete and update one record at a time but how do you go about updating adding and deleting multiple records at a time.

Example if I want to update the current stock price of all of my stocks how do I go about just creating one button that will update all the textboxes in the page with the new quotes.

Thanks

minority
08-03-2005, 03:27 AM
you basically need to do a loop for each record and store the id for each record eg

radio buttons.

<%
b = rscount("intTotal") - 1
For i = 0 TO b
radioname = "archive" & i 'Create a unique name for the radio buttons on each for loop
%>

<input name="<%=radioname %>" type="radio" value="True" <%if rsdoc("Archive") = "True" then %> checked <%end if%>>

<!-- Then your radio button would look like this. The above asp code is placed in the radiobutton to form its name and for each record it increments by 1.
You will need a hidden field to place the id of each field (Primary key) so that you can identify it when updating.
You also need a text field outside the loop to pass how many records are in the database so it would be equal to i -->


if subid = 0 then
rsDoc.Open strSQL3, strCon
Else
rsDoc.Open strSQL4, strCon
end if%>
<FORM name ="Form" method="post" action="archiveupdatesql.asp?dept_id=<%=d%>&doc_type=<%=doctype%>" >
<%
b = rscount("intTotal") - 1
For i = 0 TO b
radioname = "archive" & i 'Create a unique name for the radio buttons on each for loop
docid = "docid" & i 'Create a unique name for the hidden value on each for loop
%>
<table width = "81%" bordercolordark="#0c66aa">
<tr>
<td width ="4%">&nbsp;</td>
<td width = "8%"><img src="../../Images/bulletpoints/MenuBullet.gif" width="30" height="30"></td>
<td width = "5%"><input type="hidden" value="<%=rsdoc("Doc_ID")%>" name="<%=docid %>">&nbsp;</td>
<td width = "30%"><center class = "text">
<%=rsDoc("Doc_Name")%></center></td>
<td width = "9%">&nbsp;</td>
<td width = "20%"><center>
<%=rsDoc("Version")%> </center></td>
<td width = "13%"><center>
<input name="<%=radioname %>" type="radio" value="True" <%if rsdoc("Archive") = "True" then %> checked <%end if%>>
YES <BR>
</center></td>
<td width = "13%"><center>
<input type="radio" name="<%= radioname %>" value="False" <%if rsdoc("Archive") = "False" then %> checked <%end if%>>
NO </center></td>
</tr>
</table>
<br>
<hr width ="75%">
<%
rsdoc.movenext
Next
rsDoc.Close
rscount.close
Set strCon = Nothing
Set rsDoc = Nothing
%>
<table width ="75%">
<tr>
<td width ="10%"><input type="hidden" value="<%=i%>" name="totals"></td>
<td width ="20%"><input name="submit" type="submit" value=" Submit " ></td>
<td width ="7%"></td>
<td width ="20%"><input name="Reset" type="reset" value=" Reset " ></td>
</tr>
</table>


Here is my full code to a form that i have done that you could use as guidance.

the updating of the database is of a similar manner where you simply use the value of i in a for loop and update the database...Remeber to increment the value of radio button to get each of the names. eg archive = "archive" & b where b is the current number of times it has looped.

at51178
08-03-2005, 11:51 AM
Hi

Thanks for your response
I appologize for my ingurance but I tried to apply the update method to my code without success. Although I do understand the concept of what the code is doing I still am not able to reproduce the results that I am looking for.

Would it be possible for you to add the functionality to the below code of my site.

The below code is only for the first page of the site. I am not sure how to set up the second part that will be doing all the updating. The difference I would like between your code and my code is that I do not want to have a radio button if possible I would like the setup where I just adjust the textboxes and click update button.
Thank You

<html>
<head>
<title>My Stocks</title>
</head>
<body>
<table width=100% height=36 border=0 cellpadding=0 cellspacing=0 bgcolor=#E5EEF9>
<tr>
<th scope=col><table width=100% height=26 border=0 cellpadding=0 cellspacing=0 bgcolor=#B4CCEB>
<tr>
<th scope=col align = right ><a href = "index.asp">Home</a> | <a href = "add.html">Add</a> | <a href = "delete.asp">Delete</a> | <a href = "edit.asp">Edit</a></th>
</tr>
</table></th>
</tr>
</table>
<table font width = 100% border = 0 cellspacing = 0 cellpadding = 0>
<tr>
<th width = 15%></th>
<th width = 10%>Name</th>
<th width = 10%>Symbol</th>
<th width = 10%>Pur Date</th>
<th width = 10%>Trade Date</th>
<th width = 10%>Shares</th>
<th width = 10%>Cost</th>
<th width = 10%>Value</th>
<th width = 15%></th>
</tr>
</table>
<table align = center bgcolor = #B4CCEB width = 70%><tr><th></th></tr></table>
<form action = "edit_records.asp" name = "form" medthod = "post" >
<%
Dim adoCon
Dim rs
Dim strSQL


set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("stocks.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM stocks;"
rs.Open strSQL, adoCon


Do While not rs.EOF
icounter = icounter + 1
'Write the HTML to display the current record in the recordset
Response.Write("<table width = '100%' border = '0' cellspacing = '0' cellpadding = '0'>")
Response.Write("<tr>")
Response.Write("<th width = '15%'><input type = text name = txtid value ='" & rs("txtid") &"' size = '10'></th>")
Response.Write("<th width = '10%'><input type = text name = txtcompanyname value ='" & rs("txtcompanyname") &"' size = '10'></th>")
Response.Write("<th width = '10%'><input type = text name = txtsymbol value ='" & rs("txtsymbol") &"' size = '10'></th>")
Response.Write("<th width = '10%'><input type = text name = txtpurdate value ='" & rs("txtpurdate") &"' size = '10'></th>")
Response.Write("<th width = '10%'><input type = text name = txttradedate value ='" & rs("txttradedate") &"' size = '10'></th>")
Response.Write("<th width = '10%'><input type = text name = txtshares value ='" & rs("txtshares") &"' size = '10'></th>")
Response.Write("<th width = '10%'><input type = text name = txtcost value ='" & rs("txtcost") &"' size = '10'></th>")
Response.Write("<th width = '10%'><input type = text name = txtvalue value ='" & rs("txtvalue") &"' size = '10'></th>")
Response.Write("<th width = '15%'></th>")
Response.Write("</tr>")
Response.Write("</table>")
rs.MoveNext
Loop
Response.Write("<input type=text name=totalNumberOfRows value ='" & countrow &"' size = '10'>")
rs.Close
Set rs = Nothing
Set adoCon = Nothing
%>
<table width = "100%" align = right><tr><th><input type = submit value = "update"></th></tr></table>
<br><br>
</form>
</body>
</html>