Solved

For Each objRow In Workspace.DataTable.DataSet - Order by

Posted on 2013-01-25
5
296 Views
Last Modified: 2013-01-30
In the following code how would I do this so it orders by SalesAmountDescr?


For Each objRow In Workspace.DataTable.DataSet
           
                    Text = objRow.SalesAmountDescr
   
        Next
0
Comment
Question by:vbnetcoder
5 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38820736
You can sort using the DataView object of the datatable. Looks like you have some poor naming conventions in use. Is DataSet of type DataTable? You can use DataTable.DefaultView.Sort property


http://msdn.microsoft.com/en-GB/library/system.data.dataview.sort.aspx
0
 
LVL 7

Expert Comment

by:tipsybroom
ID: 38820764
you can sort your rowcollection with linq

// create a sorted collection
var result = Workspace.DataTable.DataSet.OrderBy(r => r.SalesAmountDescr);

foreach (var item in result) Console.WriteLine(r.SalesAmountDescr);

Open in new window

0
 

Author Comment

by:vbnetcoder
ID: 38827399
What is r in r.SalesAmountDescr?
0
 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
ID: 38829863
r is lambda function. VB syntax is almost similar to C# in all cases except of LINQ :). So, VB:
Dim result = Workspace.DataTable.DataSet.OrderBy(Function(r) r.SalesAmountDescr)
0
 

Author Closing Comment

by:vbnetcoder
ID: 38835409
ty
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

947 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

23 Experts available now in Live!

Get 1:1 Help Now