Link to home
Start Free TrialLog in
Avatar of tatton777
tatton777Flag for United States of America

asked on

I need to iterate through a DataTable and change data conditionally

I have a instantiated, loaded, DataTable with the following columns:

FeeID
FeeGroup
Comment
Price

I need to itereate through the table and anytime that FeeGroup = "R" I want that field changed to "Required".

Can anyone help?

ASKER CERTIFIED SOLUTION
Avatar of wlfs
wlfs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tatton777

ASKER

Thanks for the help. Just wanted to comment that to get the compiler to throw no warnings, I need to write the code like this:

    foreach (DataRow r in dataTable.Rows)
    {
      if (r["FeeGroup"].ToString() == "R")
      {
        r["FeeGroup"] = "Required";
      }
    }

Just a note to anyone else who might be trying this. The ReadOnly property on the TableColumn must be set to "false".

THANKS WLFS!!
Avatar of wlfs
wlfs

Yes, sorry that I forgot about the ToString().

> The ReadOnly property on the TableColumn must be set to "false".
Well, that should be fairly obvious :)

Glad I could help,
woolf