I have a DataTable. What I want to do is change the value of all rows of the Colum "X" of the DataTable.
For example:
if row value is "TRUE" then change it into "Yes" else change it into "No"
A simple loop:
foreach(DataRow row in table.Rows)
{
string oldX = row.Field<String>("X");
string newX = "TRUE".Equals(oldX, StringComparison.OrdinalIgnoreCase) ? "Yes" : "No";
row.SetField("X", newX);
}
StringComparison.OrdinalIgnoreCase enables case insensitive comparison, if you don't want "Equals" to be "Yes" simply use the == operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With