I need to iterate through a DataTable and change data conditionally

Posted on 2006-03-26
Last Modified: 2010-04-16
I have a instantiated, loaded, DataTable with the following columns:


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

Can anyone help?

Question by:tatton777
    LVL 5

    Accepted Solution

    DataTable dataTable;
    // instantiate and load dataTable
    foreach (DataRow r in dataTable.Rows) {
      if (r["FeeGroup"] == "R") {
        r["FeeGroup"] = "Required";
    LVL 1

    Author Comment

    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".

    LVL 5

    Expert Comment

    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,

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now