[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I need to iterate through a DataTable and change data conditionally

Posted on 2006-03-26
3
Medium Priority
?
225 Views
Last Modified: 2010-04-16
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?

0
Comment
Question by:tatton777
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
wlfs earned 1000 total points
ID: 16296040
DataTable dataTable;
// instantiate and load dataTable
foreach (DataRow r in dataTable.Rows) {
  if (r["FeeGroup"] == "R") {
    r["FeeGroup"] = "Required";
  }
}
0
 
LVL 1

Author Comment

by:tatton777
ID: 16296276
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!!
0
 
LVL 5

Expert Comment

by:wlfs
ID: 16296604
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

864 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