简体   繁体   中英

Clear particular column values in DataTable

I have data table with Four fields Emp_No, AmountPaid, Amount_Adjusted, Adjustment_Reason

I want to clear the values of Adjustment_Reason column

I have tried the below code :

for (int i = adjustmentTable.Rows.Count - 1; i >= 0; i--)
{
  adjustmentTable.Rows[i]["AdjustmentReason"] = DBNull.Value;
}

Its working fine. But can any one suggest me a code to achieve this by using LINQ

You can write something like this:

adjustmentTable.Rows
               .OfType<DataRow>()
               .ToList()
               .ForEach(r => r["AdjustmentReason"] = DBNull.Value);

But quite frankly I'm not sure how performant this can be for the large amount of data in your datatable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM