• 批量插入数据 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.

    }
    }


    }

    }

  • 相关阅读:
    Integer vs int
    j2ee gradle构建
    ubuntu16.04更新node.js
    阿里云centos7服务器
    使用jdbc给一张表增加多行字段
    安装mysql后,java使用jdbc连接mysql数据库
    关于异常try{}catch(){}
    计算机基础单位
    java mongodb 增删改查 工具类
    java 操作mongodb查询条件的常用设置
  • 原文地址:https://www.cnblogs.com/yangjinwang/p/4147201.html
Copyright © 2020-2023  润新知