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!

Adding Multiple Rows

Status
Not open for further replies.

girky

Programmer
Oct 24, 2002
72
US
I'm trying to add multiple rows to my table at once. I'm not really sure how but here's what I did so far.
The fields are Qnty, User, Desc
In the form to enter the info I have 10 lines and named the inputs "field1-10", as in Qnty1, Qnty2, User1, User2, etc.
On my insert asp page I want to possibly do a loop for the fields, something like
i = 1
do while i < 11
sql(i) = &quot;INSERT INTO SUB(QNTY,USER,DESC)&quot;
sql(i) = sql(i) & &quot;VALUES
('&quot; & Request.Form(&quot;QNTY(i)&quot;) & &quot;',&quot;
.......
i = i + 1
loop

Thanks.
 
for x = 1 to 10
sSql = &quot;INSERT INTO SUB(QNTY,USER,DESC)&quot;
sSql = VALUES ('&quot; & Request.Form(&quot;QNTY(x)&quot;) & &quot;',&quot;
.... );&quot;
next


at the end you will have a string with multiple sql statements. The key is the semicolon after each statement. This will work in sql server. I have not done
this with other dbs.

hth
 
I'm still getting server errors.
And it is in sql server. Any ideas?


for i = 1 to 10
sql = &quot;INSERT INTO SUB(QUANTITY,DESCRIPTION,USER)&quot;
sql = & &quot;VALUES &quot;
sql = sql & &quot;('&quot; & Request.Form(&quot;QNTY(i)&quot;) & &quot;',&quot;
sql = sql & &quot;'&quot; & Request.Form(&quot;DESC(i)&quot;) & &quot;',&quot;
sql = sql & &quot;'&quot; & Request.Form(&quot;USER(i)&quot;) & &quot;');&quot;
next i
 
If your quantity field is numeric rather than text in your db than you need to pass it without the single quotes around. Also if you are trying to build ten strings in a row with the above loop your only going to end up with a single string because your most recently created SQL statement will continue to wipe out everything in the sql variable, you need to add a sql & to the first line similar to the other lines.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
It works fine until I add the For i loop and the i after the fields: QNTY(i).
I think its the (i) thats throwing things off
 
sql = sql & &quot;('&quot; & Request.Form(&quot;QNTY(&quot; & i & &quot;)&quot;) & &quot;',&quot;
sql = sql & &quot;'&quot; & Request.Form(&quot;DESC(&quot; & i & &quot;)&quot;) & &quot;',&quot;
sql = sql & &quot;'&quot; & Request.Form(&quot;USER(&quot; & i & &quot;)&quot;) & &quot;');&quot;

you were requesting a field called QNTY(i) etc where i was equal to nothing, it was actually looking for a field called that literally Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
I had tried that right after I posted, and it still doesn't work
 
in the above code you've no continuation of the sql
sql = & &quot;VALUES &quot;
is that just an omission Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Yes i forgot that...so far it is

for i = 1 to 10
sql = sql & &quot;INSERT INTO SUB(QUANTITY,DESCRIPTION,USER)&quot;
sql = sql & &quot;VALUES &quot;
sql = sql & &quot;('&quot; & Request.Form(&quot;QNTY(&quot; & i & &quot;)&quot;) & &quot;',&quot;
sql = sql & &quot;'&quot; & Request.Form(&quot;DESC(&quot; & i & &quot;)&quot;) & &quot;',&quot;
sql = sql & &quot;'&quot; & Request.Form(&quot;USER(&quot; & i & &quot;)&quot;) & &quot;');&quot;
next i
 
it works!! i took the parenthesis out from around the i


sql = sql & &quot;('&quot; & Request.Form(&quot;QNTY&quot; & i & &quot;&quot;) & &quot;',&quot;


thanks everyone for your help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top