Click here to Skip to main content
15,881,815 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Updated 24-May-17 0:19am

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[^]
 
Share this answer
 
Comments
PTG.Jake 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 24-Dec-12 12:35pm    
Your welcome,
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900