Is there method to sort my dataset table with one or mulitple colu

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Are there any good built-in or availble functions that I can call to sort my
dataset datatalbe based on 1 or more of the table's columns?
 
Pucca,

You can do it a couple of different ways. You'll find a lot of good
examples from a Google for DataTable.Select or DataView.Sort.

Most folks use System.Data.DataView.Sort since the results are a bit easier
to deal with than the array that DataTable.Select() returns.

see this article:
http://www.akadia.com/services/dotnet_filter_sort.html

Jason Vermilllion
 
I want to pass a sorted dataset table to Crystal Report becuase I think it
might give better performance. I don't think that dataview can be passed as
a datasource to crystal and the sorted result isn't saved to the dataset
table either, right?
 
I think you can pass a DataView to setdatasource(). I've not tested it
myself but see this post:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=870964&SiteID=1

I know there used to be a bug with SetDataSource() and you had to sort the
data in a DataView then copy it back into a clone of the original DataTable.
I think this has long been fixed though. The workaround went something like
this:

System.Data.DataTable origTbl; // Your original table
DataView dv;
System.Data.DataTable sortedTbl;

dv = origTbl.DefaultView;
dv.Sort = "col1 asc, col2 asc";

// Copy the sorted view into a new table..
sortedTbl = dv.Table.Clone();
for (int i = 0; i < dv.Count; i++)
{
sortedTbl.ImportRow(dv.Row);
}

Hope this helps,
Jason Vermillion
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top