最好的方式从一个C#的DataTable批量插​​入 [英] Best way to Bulk Insert from a C# DataTable

查看:506
本文介绍了最好的方式从一个C#的DataTable批量插​​入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表我要推到数据库。我希望能说喜欢

I have a DataTable that I want to push to the DB. I want to be able to say like

myDataTable.update();

但看完MSDN 文档,显然这之后没有插入逐行。

But after reading the MSDN docs, apparently this does inserts row by row.

应当注意的是,这些陈述不以间歇过程进行;每一行都是单独更新。

It should be noted that these statements are not performed as a batch process; each row is updated individually.

我有什么办法?

编辑:我使用SQL Server 2005

I am using SQL Server 2005

推荐答案

如果使用SQL Server, SqlBulkCopy.WriteToServer(数据表)

If using SQL Server, SqlBulkCopy.WriteToServer(DataTable)

  • SqlBulkCopy.WriteToServer Method (DataTable)

或者也与SQL Server,可以将其写为.csv,并使用 BULK INSERT

Or also with SQL Server, you can write it to a .csv and use BULK INSERT

  • BULK INSERT (Transact-SQL)

如果使用MySQL,你可以写为.csv,并使用 LOAD DATA INFILE

If using MySQL, you could write it to a .csv and use LOAD DATA INFILE

  • LOAD DATA INFILE Syntax

如果使用的是Oracle,可以使用ODP数组绑定功能.NET

If using Oracle, you can use the array binding feature of ODP.NET

  • Bulk Insert to Oracle using .NET

如果SQLite的:

  • How do I bulk insert with SQLite?
  • Faster bulk inserts in sqlite3?

这篇关于最好的方式从一个C#的DataTable批量插​​入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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