Pages

Thursday, March 22, 2012

Sorting a non-SQL Dataset

So I have an ASP.NET web site and the data is coming not from a SQL Server database, but from a web service.  I have executed the Web call and gathered the data into a dataset, and I wish to sort the data inversely by job order number, floating the newest job orders to the top.

As it turns out, there is no Dataset.Sort command, but there is this.

DataRow[] SortedRows = JobsDataTable.Select("isOpen = 1", "jobOrderID desc");

This gives back a sorted (and also filtered) array of DataRows based on the criteria you use. 

Now, you can't databind to a DataRow array, but if you are using databinding, the DataGrid or DataGridView can filter and sort for you, so you wouldn't need to use this technique.



Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

No comments:

Share This!

Contact Us

Name

Email *

Message *