Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a DataTable

Status
Not open for further replies.

tadd

Programmer
Oct 28, 2001
70
US

I wrote some code to sort my DataTable. Please refer to the code below:

// -------------------------------------------
// dsData is a DataSet containing a DataTable called "Table" that is loaded with unsorted data.
// I want the data in this DataTable to be sorted by PayeeName.

DataView dvData = new DataView(dsData.Tables[0]);
dvData.Sort = "PayeeName ASC";
dsData.Tables.Remove("Table");
dsData.Tables.Add(dvData.ToTable());
// -------------------------------------------

Is this an acceptable way to sort the DataTable, or is there a better way?

Thanks for any pointers.
 
Without actually answering the question directly because to be honest I am not actual sure if this a good way or not, only that if there where 5000+ records in there it may take a while.. Could it not be sorted at the data source, assuming it is a database of some type. With an Order By Clause? If not it may be quicker to put in one and take it back out...

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top