Sorting a DataTable

I have a need to sort an existing Data Table by a given column.  I know I can sort in my stored procedure, but for processing, I may need it in an order other than what is returned and/or displayed. 

Related Articles

... and you 'll find more on the NET Development Menu

A very simple way to sort a data table is to sort the default view and then copy that back to the data table.  My data table is called oGridImage, and I am sorting on a column named PAPROJNUMBER in ascending order.

myDataTable.DefaultView.Sort = "PAPROJNUMBER ASC"
myDataTable = myDataTable.DefaultView.ToTable

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences