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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New ASP Programmer trying Multiple Inserts of records

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I have an SQL database that contains three columns in my table. Date, hour, and code are the three fields. My form on my ASP page contains these three fields but multiple lines. For each line in the ASP table I want it to create a new record in the database. I have never done ASP this type of thing before and didn't know the best way to do it. I found some sample code on multiple inserting of records and don't quite understand how there downing it. There example is a 3 row table with Product, Description, and Price as the columns. Here is there sample ASP insert. For one is this good code?? ALso why do they seem to split things by Comma? Is that the way to do it? Does someone know of a better way or example?

if request(&quot;Selected2&quot;) <> &quot;&quot; Then
productarray=split(request(&quot;Product&quot;),&quot;,&quot;)
descrarray=split(request(&quot;Descr&quot;),&quot;,&quot;)
pricearray=split(request(&quot;Price&quot;),&quot;,&quot;)
for i=0 to ubound(productarray)
if len(trim(productarray(i))) > 0 then
rs.addnew
rs(&quot;Product&quot;)=trim(productarray(i))
rs(&quot;Description&quot;)=trim(descrarray(i))
rs(&quot;Price&quot;)=trim(pricearray(i))
rs.update
end if
next
response.redirect &quot;MultipleInsert.asp&quot;
end if
%>

Second here is there Form Code.

<table width=&quot;400&quot; border=&quot;0&quot;>
<tr>
<td>Sample2</td>
<td> </td>
<td>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Insert&quot;>
</td>
</tr>
<tr>
<td>Product</td>
<td>Description</td>
<td>Price</td>
</tr>
<tr>
<td>
<input type=&quot;text&quot; name=&quot;Product&quot;>
</td>
<td>
<input type=&quot;text&quot; name=&quot;Descr&quot;>
</td>
<td>
<input type=&quot;text&quot; name=&quot;Price&quot;>
</td>
</tr>
<tr>
<td>
<input type=&quot;text&quot; name=&quot;Product&quot;>
</td>
<td>
<input type=&quot;text&quot; name=&quot;Descr&quot;>
</td>
<td>
<input type=&quot;text&quot; name=&quot;Price&quot;>
</td>
</tr>
<tr>
<td>
<input type=&quot;text&quot; name=&quot;Product&quot;>
</td>
<td>
<input type=&quot;text&quot; name=&quot;Descr&quot;>
</td>
<td>
<input type=&quot;text&quot; name=&quot;Price&quot;>
</td>
</tr>
</table>
<input type=&quot;hidden&quot; name=&quot;Selected2&quot; value=&quot;1&quot;>
</form>
 
They split the strings by comma because there are several textboxes that are named the same (Product for instance).
When such a form is submitted, the resulting value of &quot;Product&quot; is &quot;value1, value2, value3&quot;. So, to get individual values, you would separate them by comma.

I personally have never done it this way, but it sure looks good to me.

Just don't forget to close and dispose of RecordSet object

rs.Close
Set rs = Nothing <Dmitriy>
dbrom@crosswinds.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top