I am using a DataTable for some calculations in my app. I need to do the iterate trough all the rows except the first one. Is it possible?
Something like:
DataTable dt;
foreach (DataRow r in dt.Rows /*EXCEPT THE FIRST ONE*/)
{
    //do something...
}
                It's easiest to use the Skip method in LINQ to Objects for this, to skip a given number of elements: foreach (var value in sequence. Skip(1)) // Skips just one value { ... } Obviously just change 1 for any other value to skip a different number of elements...
use Datatable. rows(0) this will give you the first row in the datatable.
A table header row is the top row of a table that acts as a title for the type of information they will find in each column.
LINQ is your friend:
DataTable dt;
foreach (DataRow r in dt.Rows.Cast<DataRow>().Skip(1))
{
    //do something...
}
The call to Cast() is required here since DataTable.Rows implements the non-generic IEnumerable, and linq's extension methods are only available for IEnumerable<T>
You also have another option:
DataTable dt;
foreach (DataRow r in dt.AsEnumerable().Skip(1))
{
    //do something...
}
                        Ok you got your answers but in case you donT want to use linq. Check the index of the row in the table:
            foreach (DataRow row in m_dtMatrix.Rows)
            {
                if (m_dtMatrix.Rows.IndexOf(row) != 0)
                {
                    ...
                }
            }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With