Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
I need to insert a row in a table for the number a user enters into a text box.
 
example: user puts the number "6" into textbox, and clicks the button. I want it to insert 6 rows into the database table.
 
can anyone give me an example on how to do this.
sql database.
Posted 24-Dec-12 6:55am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Look here,
 
http://www.w3schools.com/sql/sql_insert.asp[^]
 
To insert 6 records use a for loop for the number of records
 
http://www.dotnetperls.com/for-vbnet[^]
  Permalink  
Comments
Member 8197993 at 24-Dec-12 12:32pm
   
Thanks Dino your second link helped me alot. I was stuck on trying to use a "do while". problem solved.
DinoRondelly at 24-Dec-12 12:35pm
   
Your welcome,
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Here is a very good example of creating stored procedures to supply the future functionality of what your wanting to do on the SQL side of things HERE:
 
http://blog.sqlauthority.com/2009/09/23/sql-server-insert-values-of-stored-procedure-in-table-use-table-valued-function/[^]
 
Then depending on where your data is coming from could be in the Stored Procedure to collect the data for the values or you would have to send in that value.
 
On the C# side of things, you can do many different options to loop through the data needs:
 
While example:
http://www.google.com/url?sa=t&rct=j&q=loops%20in%20c%23&source=web&cd=6&cad=rja&ved=0CFgQFjAF&url=http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2F2aeyhxcd(v%3Dvs.71).aspx&ei=DY7YUM20McikqQG1rYGABw&usg=AFQjCNHqyjWzbpqw721Gz5SZ44_yGXBqNw&bvm=bv.1355534169,d.aWM[^]
 
FOR supplied above but heres another: (Visual Studio version not relevent in this example)
 
http://msdn.microsoft.com/en-us/library/ch45axte.aspx[^]
 

Foreach, Do etc... examples:
 
http://msdn.microsoft.com/en-us/library/ms228598(v=vs.90).aspx[^]
 
Hope that helps.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.150302.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100