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


DataTable pull Row column based on Index

Posted on 2011-05-10
Medium Priority
Last Modified: 2012-05-11
I have the following code:

foreach (DataRow rRow in Table.Rows)
       if (rRow["Year"].ToString().Trim() == year.ToString())
                            total      = float.Parse(Table.Rows[0]["Total"].ToString().Trim()) / 100;

Now, this code pulls from Row index 0 all the time.  The data table contains many rows, and I would like the Row that the data pulls from to be a specific index.  I would like the index to pull where the rRow"Year" column is equal to the "year" variable and I don't know how to do this.  Thanks!
Question by:melli111
LVL 13

Accepted Solution

jeebukarthikeyan earned 2000 total points
ID: 35730630

try this way

for(int i=0;i<Table.Rows.count;i++)
if Table.Rows[i]["Year"].ToString().Trim() == year.ToString())
  total      = float.Parse(Table.Rows[i]["Total"].ToString().Trim()) / 100;


Open in new window


LVL 15

Author Comment

ID: 35738865
Thank you sir

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

825 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