473,396 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataTable order by

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


Jul 21 '06 #1
3 8268
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.

"Lowry Smith" <Lo**********@hotmail.comwrote in message
news:uj**************@TK2MSFTNGP02.phx.gbl...
>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


Jul 21 '06 #2
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.
"Lowry Smith" <Lo**********@hotmail.comwrote in message
news:uj**************@TK2MSFTNGP02.phx.gbl...
>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


Jul 21 '06 #3
Just a clarification. One order attribute effects only one column.

"State, ZipCode DESC" is equal to "State ASC, ZipCode DESC";
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"Kevin Spencer" <uc*@ftc.govwrote in message
news:OB**************@TK2MSFTNGP05.phx.gbl...
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.
"Lowry Smith" <Lo**********@hotmail.comwrote in message
news:uj**************@TK2MSFTNGP02.phx.gbl...
>>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



Jul 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ev | last post by:
I have a database table in SQL Server that has a self join. In C# I have a DataTable with a self-join. I have defined a foreign key constraint on the DataTable for the self join. The...
3
by: Pradeep | last post by:
Hi, I am storing the DataTable in a ViewState. ViewState("mydata") = dsRedemption.T_Redemption_Dtl Then I am casting the ViewState into a DataTable variable. Dim x As New DataTable x =...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
7
by: GaryB | last post by:
I have an untyped datatable that has financial numbers and controls that were populated by code (not a simple fill from a DA). Now I want to insert subtotals into it. I wrote a sub to do so that...
3
by: emailtonitin | last post by:
Hi, I am having a problem with the default sorting mechanism employed by the datatable.select method - I have a datatable having rows (simplified for clarity) - name ----- c a
12
by: Doug Bell | last post by:
Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String...
0
by: Nathan Franklin | last post by:
Hello Guys, I have been trying to work this our for so long, but I just can't seem to find the answer. I am loading a datatable from a an access database using an oledbdataadapter. I then...
10
by: dauphian | last post by:
Hello, I am new to .net and am trying to build a report application that queries 4 different tables based on a id, and I need to return them in the same table for easy viewing. Basically, I...
6
by: David P. Donahue | last post by:
I've been looking around for ways to sort the rows in a DataTable, and everything seems to point to just changing the Sort property on that DataTable's DefaultView property. That's all well and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.