如何填充IDataReader从.csv用于与SqlBulkCopy.WriteToServer(IDataReader) [英] How to populate IDataReader from .csv for use with SqlBulkCopy.WriteToServer(IDataReader)
问题描述
今天有人提到,使用IDataReader版本的WriteToServer(注意:数据存储在.csv文件中)比使用大型.csv文件的数据表更快。不幸的是,我不知道如何实际工作/应该实现的信息。
只有链接,发现如下:
http: //www.developerfusion.com/article/122498/using-sqlbulkcopy-for-high-performance-inserts/
- 数据实际存储在哪里?
- 我会在
时间导入一行吗? - 如何分割特定字符,即',' b $ b case?
这是很棘手的吗?
-Import-Exportrel =nofollow> this 。它解释了如何使用ODBC提供程序读取CSV文本,然后使用 SqlBulkCopy
将其导入到数据库。例如:
using(var con = new OdbcConnection(
Driver = {Microsoft Text Driver(* .csv )};+
Dbq = c:\\somepath\\;+
Extensions = csv))
{
con.Open );
using(var cmd = new OdbcCommand(select * from [+ myCsvFileName +],con))
{
using(IDataReader reader = cmd.ExecuteReader())
{
// Do whatever
}
}
}
Someone mentioned today that using the IDataReader version of WriteToServer (Note: Data is stored in a .csv file) would be quicker than using datatables for large .csv files. Unfortunately im struggling to find information on how this actually works/should be implemented.
only link i found is below:
http://www.developerfusion.com/article/122498/using-sqlbulkcopy-for-high-performance-inserts/
- Where is the data actually stored?
- Would i be importing one row at a time?
- How do you split about specific characters ie ',' in this case?
Is this something which is quite tricky?
Thanks
See this. It explains how to read a CSV using the ODBC provider for text, and then use SqlBulkCopy
to import it into a DB. For example:
using(var con = new OdbcConnection(
"Driver={Microsoft Text Driver (*.csv)};" +
"Dbq=c:\\somepath\\;" +
"Extensions=csv"))
{
con.Open();
using(var cmd = new OdbcCommand("select * from [" + myCsvFileName + "]", con))
{
using(IDataReader reader = cmd.ExecuteReader())
{
// Do whatever
}
}
}
这篇关于如何填充IDataReader从.csv用于与SqlBulkCopy.WriteToServer(IDataReader)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!