Search code examples
c#asp.netdatatable

Update multiple rows in datatable without loop


I have two datatable with conditions in application and want some processing for multiple rows to update column value.

For example:

I have datatable1 with 10000 rows. I want to filter rows by datatable.select("condition") and as per condition, I want to update row values.

If for any condition, I found 20 rows from datatable. I want to update those 20 records in one shot. Not in any loop. I have datarow array for those values to update in datable.


Solution

  • You can try out the following linq,

    DataTable recTable = new DataTable();
    
    // do stuff to populate table
    
    recTable.Select(string.Format("[code] = '{0}'", someName)).ToList<DataRow>().ForEach(r => r["Color"] = colorValue);
    

    You can substitute your columns and values here...