Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
I need to know how to sort the records in a datatable
based on id column(which has a type of integer) but without using
dt.defaultview because i'm not using databinding.
Posted
Comments
Nathan Stiles 18-Apr-12 23:12pm    
DataTable.Select Method (String, String) may help. See http://msdn.microsoft.com/en-us/library/way3dy9w.aspx

1 solution

As far as I know there is no Sort method available to directly sort the Rows of a DataTable.
One option is to use DefaultView, sort it and then use the ToTable method to obtain a sorted datatable, as shown below
C#
DataView dataView = DataTable1.DefaultView;
dataView.Sort = "Id";
DataTable sortedTable = dataView.ToTable();

Other option is to use DataTable.Select method as as mentioned by Nathan Stiles in the comment to the question, but with this method an Array of DataRow objects is obtained.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900