none
Count Datatable Rows? RRS feed

  • Question

  • I have a datatable:

    11/11/2011        active

    11/12/2011        idle

    11/13/2011        idle

    I need to know the number of 'idle' rows. How can I use Linq to achieve this?

    Thanks.

    Saturday, January 7, 2012 6:26 PM

Answers

  • Problem solved:

     

            public int GetRowCount(string val)
            {
                int rowCount = 0;
                try
                {
                    rowCount = (from DataRow row in MyDataTable.Rows where (string)row["State"] == val select row).Count();
                }
                catch
                {
                }
                return rowCount;
            }

    Saturday, January 7, 2012 6:46 PM

All replies

  • Problem solved:

     

            public int GetRowCount(string val)
            {
                int rowCount = 0;
                try
                {
                    rowCount = (from DataRow row in MyDataTable.Rows where (string)row["State"] == val select row).Count();
                }
                catch
                {
                }
                return rowCount;
            }

    Saturday, January 7, 2012 6:46 PM
  • Hi Y2011,

    I'm glad to hear that the issue has been solved, and thanks for sharing your solution. With your help, the forum will be better and better.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, January 10, 2012 2:04 AM
    Moderator