如何根据用户输入将多行插入sql数据库? [英] How to insert multiple rows into sql database depending on user input?

查看:107
本文介绍了如何根据用户输入将多行插入sql数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在表格中插入一行,用户输入一个文本框。



例如:用户将数字6放入文本框,然后单击按钮。我希望它在数据库表中插入6行。



任何人都可以给我一个如何做到这一点的例子。

sql database 。

解决方案

看这里,



http://www.w3schools.com/sql/sql_insert.asp [ ^ ]



要插入6条记录,请使用for循环记录的数量



http://www.dotnetperls.com/for-vbnet [ ^ ]


这里是一个很好的例子,创建存储过程来提供你想要在SQL端做什么的未来功能:



http://blog.sqlauthority.com/2009/09/23/sql-server-insert-values-of-stored-procedure-in- table-use-table-valued-function / [ ^ ]



然后取决于您的数据来自哪里可以在存储过程中收集值的数据,或者您必须发送该值。



在C#侧事情,你可以做很多不同的选择来循环数据需求:



虽然例子:

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-我们%2Flibrary%2F2aeyhxcd(v%的3Dvs.71)的.aspx&安培; EI = DY7YUM20McikqQG1rYGABw&安培; USG = AFQjCNHqyjWzbpqw721Gz5SZ44_yGXBqNw&安培; BVM = bv.1355534169,d。 aWM [ ^ ]



FOR上面提供但另外是另一个:(Visual Studio在这个例子中版本不相关)



http ://msdn.microsoft.com/en-us/library/ch45axte.aspx [ ^ ]





Foreach,Do等...示例:



http://msdn.microsoft.com/en-us/library/ms228598(v=vs.90).aspx [ ^ ]



希望有所帮助

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.

解决方案

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[^]


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.


这篇关于如何根据用户输入将多行插入sql数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆