DataTable order by

L

Lowry Smith

I am building the datatable (Name: dtCutomer) with Column1, Column2,
Column3.

What is the syntax to sort the data in a datatable on Column1.

Vb.Net and .Nete 1.1.

Thank you,

Lowry
 
M

Marina Levit [MVP]

You have to create a DataView on it, and set the sort there. This will give
you a sorted view of the data, without actually sorting the underlying
datatable. You can use a DataView to bind to objects as you would a
datatable, and so on.
 
K

Kevin Spencer

You can't sort the DataTable, except via the Query, View, or Stored
Procedure that populates it. You *can* sort the DefaultView of the
DataTable, or any DataView that is associated with the DataTable. This is
done via the Sort property of the DataView. This is a string which specifies
the column or columns to sort on, and the order (ASC or DESC).

Example:

myTable.DefaultView.Sort = "State, ZipCode DESC";

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
 
E

Eliyahu Goldin

Just a clarification. One order attribute effects only one column.

"State, ZipCode DESC" is equal to "State ASC, ZipCode DESC";
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top