zoukankan      html  css  js  c++  java
  • 块拷贝

    /// <summary>
    /// 块拷贝
    /// </summary>
    /// <param name="source"></param>
    /// <param name="connectionString"></param>
    /// <param name="destinationTableName"></param>
    public static void SaveToSqlServer(DataTable source, string connectionString, string destinationTableName)
    {
    try
    {

    using (SqlBulkCopy bcp = new SqlBulkCopy(connectionString))
    {
    bcp.DestinationTableName = destinationTableName;
    bcp.BatchSize = 20000;
    bcp.BulkCopyTimeout = 1200;
    int columnIdex = 0;
    foreach (DataColumn column in source.Columns)
    {
    bcp.ColumnMappings.Add(columnIdex, columnIdex);
    columnIdex++;
    }
    bcp.WriteToServer(source);
    }
    }
    catch (Exception ex)
    {
    throw ex;
    }
    }


    public static void SaveToSqlServer(DataTable source, string connectionString, string destinationTableName, System.Collections.Generic.Dictionary<string, string> mappingColumns)
    {
    using (SqlBulkCopy bcp = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.UseInternalTransaction))
    {
    bcp.DestinationTableName = destinationTableName;
    bcp.BatchSize = 20000;
    bcp.BulkCopyTimeout = 1200;
    try
    {
    foreach (string columnName in mappingColumns.Keys)
    {
    SqlBulkCopyColumnMapping columnMapID = new SqlBulkCopyColumnMapping(columnName, mappingColumns[columnName]);
    bcp.ColumnMappings.Add(columnMapID);
    }
    bcp.WriteToServer(source);
    }
    catch (Exception ex)
    {
    throw new Exception(ex.Message);
    }
    }
    }

  • 相关阅读:
    BZOJ3473: 字符串
    BZOJ1088: [SCOI2005]扫雷Mine
    跪啃SAM
    BZOJ3932: [CQOI2015]任务查询系统
    BZOJ3545: [ONTAK2010]Peaks
    06.约束
    05.数据表的创建与简单操作
    04.数据库的创建
    安卓6.0后运行时权限封装
    OkGo使用缓存
  • 原文地址:https://www.cnblogs.com/kevin1988/p/3590873.html
Copyright © 2011-2022 走看看