Print Page | Close Window

insert multiple rows

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=25221
Printed Date: 28 March 2026 at 7:54am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: insert multiple rows
Posted By: zMaestro
Subject: insert multiple rows
Date Posted: 28 January 2008 at 1:00pm
Hi,
What's the simplest way to insert multiple rows of data from one form into a database?
 



Replies:
Posted By: michael
Date Posted: 28 January 2008 at 1:36pm
Not sure what type of form you are talking about. Depending on the DB you can simply paste from e.g. Excel to SQL. If it's a CSV you can write a little insert statement like
Insert into table1 (col1,col2,col3)
Select col1,col2,col3 from csvprovider

Again, it really depends where your data is coming from.


-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: zMaestro
Date Posted: 28 January 2008 at 3:13pm
It is coming from a webform, where user should add 5 rows per submit.
like in tell a friend form, the user enters up to 5 email addresses, each should be inserted in a new row in the table,


Posted By: zMaestro
Date Posted: 28 January 2008 at 3:15pm
Originally posted by michael michael wrote:

If it's a CSV you can write a little insert statement like
Insert into table1 (col1,col2,col3)
Select col1,col2,col3 from csvprovider
is there any example for this? if I want to insert from a csv file on server?


Posted By: michael
Date Posted: 28 January 2008 at 5:53pm
If you use classic ASP you would have to parse the file and read it in. Or you can setup a DSN to that CSV file and do basic SQL queries with it.

To insert from a web form into 5 different rows, you would just Request.Form each field and concatenate to a sql string, of course making sure each field is populated.


-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Scott07
Date Posted: 17 February 2008 at 3:15pm
If the database is mysql then you can run one insert that creates more than one record like

insert into table(col) values('bob'), ('jim'), ('ted');

(though double check the syntax as that might not be right)


-------------
http://www.worldsofwar.co.uk - Worlds of War II


Posted By: alemcherry
Date Posted: 02 March 2008 at 8:09pm
insert into tablename (col1, col2) values (val11, val12) (val21, val22) (val31, val33)


Posted By: ffffffrabbit
Date Posted: 11 February 2011 at 4:01pm
Classic ASP how do I do this:

insert into tablename (col1, col2) values (val11, val12) (val21, val22) (val31, val33)

[CODE]
< ="utf-8"><FORM METHOD="POST" ACTION="data_in.asp" NAME="FORMNAME">
..... do while Not rs.eof
%>
<input type="hidden" value="<%=rs("value_a" Name="VALUEA">
<input type="text" name="TEXT_A">
< ="utf-8"><input type="text" name="TEXT_B">
< ="utf-8"><input type="text" name="TEXT_C">

<%
rs.MoveNext
loop
rs.Close
set rs = nothing
%>
</FORM>

< ="utf-8">[CODE]
< ="utf-8">


Posted By: gotlivechat
Date Posted: 17 February 2011 at 1:20am
ffffrabbit has it right except for leaving out the database connection string information as well. You'll just loop through the REQUEST.FORM values to get them, then do an INSERT into the db of your choice.
Don't forget to SCRUB the data (meaning: check it for valid values before doing an insert) and consider using stored procedures to do so; else you may find your web form being subjected to SQL Injection attacks.


-------------
Adam Rasio
Live Chat Software Developer

http://www.GotLiveChat.com" rel="nofollow - www.GotLiveChat.com



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net