c# 的导入功能SqlBulkCopy
private static void DataTableToSQLServer( DataTable dt)
{
string connectionString = GetConnectionString();
using (SqlConnection destinationConnection =new SqlConnection(connectionString))
{
destinationConnection.Open();
using (SqlBulkCopy bulkCopy =new SqlBulkCopy(destinationConnection))
{
try
{
bulkCopy.DestinationTableName = "T_EIInformation";//要插入的表的表明
bulkCopy.ColumnMappings.Add("Email", "Email");//映射字段名 DataTable列名 ,数据库 对应的列名
bulkCopy.ColumnMappings.Add("author", "author");
bulkCopy.ColumnMappings.Add("Title", "Title");
bulkCopy.ColumnMappings.Add("Type", "Type");
bulkCopy.ColumnMappings.Add("confName", "confName");
bulkCopy.ColumnMappings.Add("Language", "Language");
bulkCopy.ColumnMappings.Add("Publicationyear", "Publicationyear");
bulkCopy.ColumnMappings.Add("Conferencelocation", "Conferencelocation");
bulkCopy.WriteToServer(dt);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
// Close the SqlDataReader. The SqlBulkCopy
// object is automatically closed at the end
// of the using block.
}
}
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。