• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

DataTable pull Row column based on Index

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!
0
melli111
Asked:
melli111
1 Solution
 
jeebukarthikeyanCommented:
hi,

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


}


jeebu
0
 
melli111SharePoint Administrator / DeveloperAuthor Commented:
Thank you sir
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now