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

loop through datatable in ascending order

Hi experts
when I loop through datatable with the following code it starts at the top , but i would like to start at the bottom

for each row as datarow in dt.rows
next

thanks
0
b001
Asked:
b001
1 Solution
 
COACHMAN99Commented:
try creating a recordset (based on a query) ordered DESC (or ASC) and, for each row in recordset

see http://support.microsoft.com/kb/168336
0
 
Fernando SotoRetiredCommented:
Hi b001;

If you change your For Each loop as follows it will give you what you want.

For Each row As DataRow In dt.AsEnumerable().Reverse()
    ' ....
Next  

Open in new window

0
 
ArkCommented:
For each r As DataRow In dt.Select("","SortColumnName DESC", _
                               DataViewRowState.CurrentRows
Next

Open in new window

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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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