内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/17469349/mapping-columns-in-a-datatable-to-a-sql-table-with-sqlbulkcopy
我想知道在将数据添加到数据库之前,我将能够将数据库表中的coloumn映射到c#中的datatable
using (SqlBulkCopy s = new SqlBulkCopy(conn))
{
s.DestinationTableName = destination;
s.WriteToServer(Ads_api_ReportData);
}
你可能需要一些东西
public void BatchBulkCopy(DataTable dataTable, string DestinationTbl, int batchSize)
{
// Get the DataTable
DataTable dtInsertRows = dataTable;
using (SqlBulkCopy sbc = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity))
{
sbc.DestinationTableName = DestinationTbl;
// Number of records to be processed in one go
sbc.BatchSize = batchSize;
// Add your column mappings here
sbc.ColumnMappings.Add("field1","field3");
sbc.ColumnMappings.Add("foo","bar");
// Finally write to server
sbc.WriteToServer(dtInsertRows);
}
}
参考: How to use SqlBulkCopyColumnMappingCollection?
.
.
Seel也是 http://www.codeproject.com/Articles/18418/Transferring-Data-Using-SqlBulkCopy
代码日志版权声明:
翻译自:http://stackoverflow.com/questions/17469349/mapping-columns-in-a-datatable-to-a-sql-table-with-sqlbulkcopy
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 使用MyBatis进行数据库映射
- Go语言中映射表map的使用
- python – 使用GLSL的OpenGL阴影映射
- 使用Gradle插件生成资源ID映射文件
- 使用内存映射 I/O 实现 Posix 消息队列
- 使用IDAPython自动映射二进制文件替换默认函数名
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Hit Refresh
Satya Nadella、Greg Shaw / HarperBusiness / 2017-9-26 / USD 20.37
Hit Refresh is about individual change, about the transformation happening inside of Microsoft and the technology that will soon impact all of our lives—the arrival of the most exciting and disruptive......一起来看看 《Hit Refresh》 这本书的介绍吧!