0

I have an issue for the slowness by updating datatable column. below is the code . Its working but taking much time to update 8000 records in the datatable. Any suggestion please

DataTable dtManufacture = _IDataaccessLayer.GetSqlTableData(_sqlConnectionString, "dbo.Manufacturer");

foreach (DataRow row in dtOracleData.Rows)
{
    DataRow rowsToUpdate = dtManufacture.AsEnumerable().FirstOrDefault(r => r.Field<string>("Code") == row.Field<string>("CODE"));
    row.SetField("CODE", rowsToUpdate.Field<int>("Id"));
}
Dai
  • 141,631
  • 28
  • 261
  • 374
  • You should do the `UPDATE` directly in SQL instead of via `DataTable` (I assume you're using a `DataAdapter` internally). You'll need to use a UDT to efficiently pass bulk data into an Oracle database: https://stackoverflow.com/questions/12712355/how-to-pass-a-table-valued-parameter-from-c-sharp-to-oracle-stored-procedure – Dai Mar 10 '21 at 13:49
  • 1
    DataAdapter is a *legacy* class that was never built to perform batch operations. It will executed each UPDATE statement separately. Even if you put all statements in a single file,this is still 8000 UPDATEs instead of 1 update with 8000 rows – Panagiotis Kanavos Mar 10 '21 at 13:52

0 Answers0