2011-10-17 35 views

回答

7

我会结合this CSV readerSqlBulkCopy;即

using (var file = new StreamReader(path)) 
using (var csv = new CsvReader(file, true)) // true = has header row 
using (var bcp = new SqlBulkCopy(connection)) { 
    bcp.DestinationTableName = "TableName"; 
    bcp.WriteToServer(csv); 
} 

它使用大容量复制API做的插入,同时采用了全托管(和快速)IDataReader实现(重要的是,这的数据,而不是一次加载它所有) 。