Guest User

Untitled

a guest
May 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. public class DataTableForBulkInsert
  2. {
  3. public static DataTable CreateDataTable()
  4. {
  5. var dataTable = new DataTable();
  6.  
  7. dataTable.Columns.Add(new DataColumn("Id", typeof(int)));
  8. dataTable.Columns.Add(new DataColumn("Description", typeof(string)));
  9.  
  10. return dataTable;
  11. }
  12.  
  13. public static void MergeListInDataTable(DataTable dataTable, IEnumerable<Record> recordList)
  14. {
  15. Parallel.ForEach(
  16. recordList,
  17. (record) =>
  18. {
  19. lock (dataTable)
  20. {
  21. dataTable.Rows.Add(
  22. record.Id,
  23. record.Description
  24. );
  25. }
  26. });
  27.  
  28. }
  29. }
Add Comment
Please, Sign In to add comment