zoukankan      html  css  js  c++  java
  • SqlBulkCopy的一个例子

     1 public bool InsertAll(IList<NewStockLuoPan> list)
     2         {
     3             DataTable dt = new DataTable();
     4             dt.Columns.Add("StockNo",typeof(string));
     5             dt.Columns.Add("Angel", typeof(int));
     6             dt.Columns.Add("YesterDayAmountIn", typeof(decimal));
     7             dt.Columns.Add("TwoDayAmountInTest", typeof(string));
     8             dt.Columns.Add("YesterDay10AmountIn", typeof(decimal));
     9             dt.Columns.Add("TenDayAmountInTest", typeof(string));
    10             dt.Columns.Add("CreatedDate", typeof(DateTime));
    11 
    12             foreach (var item in list)
    13             {
    14                 DataRow dr = dt.NewRow();
    15                 dr["StockNo"] = item.StockNo;
    16                 dr["Angel"] = item.Angel;
    17                 dr["YesterDayAmountIn"] = item.YesterDayAmountIn;
    18                 dr["TwoDayAmountInTest"] = item.TwoDayAmountInTest;
    19                 dr["YesterDay10AmountIn"] = item.YesterDay10AmountIn;
    20                 dr["TenDayAmountInTest"] = item.TenDayAmountInTest;
    21                 dr["CreatedDate"] = item.CreatedDate;
    22 
    23                 dt.Rows.Add(dr);
    24             }
    25 27             using (SqlBulkCopy sqlBC=new SqlBulkCopy(connstr))
    28             {
    29                 sqlBC.DestinationTableName = "dbo.table";
    30                 sqlBC.ColumnMappings.Add("StockNo", "StockNo");
    31                 sqlBC.ColumnMappings.Add("Angel", "Angel");
    32                 sqlBC.ColumnMappings.Add("YesterDayAmountIn", "YesterDayAmountIn");
    33                 sqlBC.ColumnMappings.Add("TwoDayAmountInTest", "TwoDayAmountInTest");
    34                 sqlBC.ColumnMappings.Add("YesterDay10AmountIn", "YesterDay10AmountIn");
    35                 sqlBC.ColumnMappings.Add("TenDayAmountInTest", "TenDayAmountInTest");
    36                 sqlBC.ColumnMappings.Add("CreatedDate", "CreatedDate");
    37                 sqlBC.WriteToServer(dt);
    38             }
    39             return true;
    40         }
  • 相关阅读:
    大数加法、乘法实现的简单版本
    hdu 4027 Can you answer these queries?
    zoj 1610 Count the Colors
    2018 徐州赛区网赛 G. Trace
    1495 中国好区间 尺取法
    LA 3938 动态最大连续区间 线段树
    51nod 1275 连续子段的差异
    caioj 1172 poj 2823 单调队列过渡题
    数据结构和算法题
    一个通用分页类
  • 原文地址:https://www.cnblogs.com/zhuangke668/p/4543807.html
Copyright © 2011-2022 走看看