将列表(整数)插入 SQL Server 表 [英] Insert List(Of Integer) into SQL Server Table
问题描述
在 VB.NET/ADO.NET 中是否有一种快速有效的方法可以将 Geneneric.List(Of Integer)
中的大量数据插入到 SQL Server 表中,除了通过列表循环并发出单独的 INSERT
命令?我仅限于 .NET 3.5 和 SQL Server 2005.
Is there a fast, efficient way in VB.NET/ADO.NET to insert large amount of data from Geneneric.List(Of Integer)
into SQL Server table besides looping thru the list and issuing individual INSERT
commands? I am limited to .NET 3.5 and SQL Server 2005.
谢谢!
推荐答案
将 XML 与存储过程的所有更改一起发送.
Ship XML with all the changes to a stored procedure.
这里有一个老例子:
这是一个较小的示例,但显示了基础知识.
Here is a smaller example, but shows the basics.
将 xml 发送到存储过程.将 xml 粉碎到 @variable 或 #temp 表.使用@variable 或#temp 表执行更新/插入(或合并/UPSERT).
Send xml to stored procedure. Shred the xml to a @variable or #temp table. Do your UPDATES / INSERTS (or MERGE/UPSERT) using the @variable or #temp table.
另一个例子.
我喜欢做的是创建一个强大的数据集.将您的数据放入强数据集.然后将 ds.GetXml() 发送到存储过程.
What I like to do is create a strong dataset. Put your data into the strong dataset. Then send the ds.GetXml() to the stored procedure.
这样,您就可以获得强类型(使用强数据集),而且您不必编写自己的 xml-maker,您可以使用 .GetXml().提示:创建强数据集后,删除命名空间(tempuri 或类似的东西)
That way, you get strong typing (using the strong dataset), and you don't have to write your own xml-maker, you piggy back off of .GetXml(). Hint: After creating the strong dataset, remove the namespace (tempuri or something like that)
这篇关于将列表(整数)插入 SQL Server 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!