DataTable pull Row column based on Index

Posted on 2011-05-10
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


    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

    Thank you sir

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    731 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