private DataTable GetTableSchema() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn("ID",typeof(int)), new DataColumn("WORKDAY",typeof(DateTime)), new DataColumn("WORKSN",typeof(int)), new DataColumn("PLANID",typeof(int))}); return dt; } public void BatchInsert(List<GuardTour_WorkDays> workdays) { DataTable dt = GetTableSchema(); for (int i = 0; i < workdays.Count; i++) { DataRow dr = dt.NewRow(); dr["WORKDAY"] = workdays[i].WORKDAY; dr["WORKSN"] = workdays[i].WORKSN; dr["PLANID"] = workdays[i].PLANID; dt.Rows.Add(dr); } GuardTourWorkDaysDAL.BulkBatchInsert(dt); }
/******************************** GuardTourWorkDaysDAL**************************************************
public void BulkBatchInsert(System.Data.DataTable dt)
{
SqlBulkCopy bulkCopy = new SqlBulkCopy(this.Context.Data.ConnectionString);
bulkCopy.DestinationTableName = "GuardTour_WorkDays";
bulkCopy.BatchSize = dt.Rows.Count;
bulkCopy.WriteToServer(dt);
}