public bool InsertAll(IList<NewStockLuoPan> list)
{
DataTable dt = new DataTable();
dt.Columns.Add("StockNo",typeof(string));
dt.Columns.Add("Angel", typeof(int));
dt.Columns.Add("YesterDayAmountIn", typeof(decimal));
dt.Columns.Add("TwoDayAmountInTest", typeof(string));
dt.Columns.Add("YesterDay10AmountIn", typeof(decimal));
dt.Columns.Add("TenDayAmountInTest", typeof(string));
dt.Columns.Add("CreatedDate", typeof(DateTime)); foreach (var item in list)
{
DataRow dr = dt.NewRow();
dr["StockNo"] = item.StockNo;
dr["Angel"] = item.Angel;
dr["YesterDayAmountIn"] = item.YesterDayAmountIn;
dr["TwoDayAmountInTest"] = item.TwoDayAmountInTest;
dr["YesterDay10AmountIn"] = item.YesterDay10AmountIn;
dr["TenDayAmountInTest"] = item.TenDayAmountInTest;
dr["CreatedDate"] = item.CreatedDate; dt.Rows.Add(dr);
}
using (SqlBulkCopy sqlBC=new SqlBulkCopy(connstr))
{
sqlBC.DestinationTableName = "dbo.table";
sqlBC.ColumnMappings.Add("StockNo", "StockNo");
sqlBC.ColumnMappings.Add("Angel", "Angel");
sqlBC.ColumnMappings.Add("YesterDayAmountIn", "YesterDayAmountIn");
sqlBC.ColumnMappings.Add("TwoDayAmountInTest", "TwoDayAmountInTest");
sqlBC.ColumnMappings.Add("YesterDay10AmountIn", "YesterDay10AmountIn");
sqlBC.ColumnMappings.Add("TenDayAmountInTest", "TenDayAmountInTest");
sqlBC.ColumnMappings.Add("CreatedDate", "CreatedDate");
sqlBC.WriteToServer(dt);
}
return true;
}
05-01 07:21