473,508 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting a DataTable in a DataSet

Is there an easy way to sort a DataTable in a DataSet? I've tried a variety
of ideas, but none of them seems to work. I'm reading in the data from an
XML file and I want to sort the list of results, one of the "tables", by
date then send the DataSet off for further processing. Any suggestions
would be greatly appreciated.

TIA

Brad
Sep 18 '06 #1
3 1507
Get the DefaultView for the table and then set the Sort property. Something
like:

ds.Tables[0].DefaultView.Sort = "DateColumn ASC"
/claes

"Brad" <br************@roche.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Is there an easy way to sort a DataTable in a DataSet? I've tried a
variety of ideas, but none of them seems to work. I'm reading in the data
from an XML file and I want to sort the list of results, one of the
"tables", by date then send the DataSet off for further processing. Any
suggestions would be greatly appreciated.

TIA

Brad

Sep 18 '06 #2
Brad,

I don't believe the dataset or datatable has a way to physically re-arrange
rows to be in some sorted order, which sounds like what you want.

You can, of course, sort a view of the data, such as the defaultview of the
datatable. But the rows in the datatable will not be re-arranged.

Kerry Moorman
"Brad" wrote:
Is there an easy way to sort a DataTable in a DataSet? I've tried a variety
of ideas, but none of them seems to work. I'm reading in the data from an
XML file and I want to sort the list of results, one of the "tables", by
date then send the DataSet off for further processing. Any suggestions
would be greatly appreciated.

TIA

Brad
Sep 18 '06 #3
Brad,

As Cor pointed out in another newsgroup, the .Net 2.0 version of the
dataview has a ToTable method. You can use a dataview to sort the rows of a
datatable and then use ToTable to create a new data table with rows that will
be in sorted order.

Kerry Moorman
"Kerry Moorman" wrote:
Brad,

I don't believe the dataset or datatable has a way to physically re-arrange
rows to be in some sorted order, which sounds like what you want.

You can, of course, sort a view of the data, such as the defaultview of the
datatable. But the rows in the datatable will not be re-arranged.

Kerry Moorman
"Brad" wrote:
Is there an easy way to sort a DataTable in a DataSet? I've tried a variety
of ideas, but none of them seems to work. I'm reading in the data from an
XML file and I want to sort the list of results, one of the "tables", by
date then send the DataSet off for further processing. Any suggestions
would be greatly appreciated.

TIA

Brad

Sep 20 '06 #4

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

Similar topics

11
16356
by: Nikki | last post by:
Is it possible to sort a dataset rather than a dataview? I have a web service that returns a dataset which I would like to sort before returning it (this is so the sorting is standardised and so...
4
10022
by: suzy | last post by:
hello. how can i sort data in a dataset? all the examples i have seen on msdn, etc are sorting a dataview. this works fine, but i want to return the results in xml and the dataview doesn't...
2
1598
by: ddaniel | last post by:
I have read many posts and seen many papers on the different techniques for sort and filtering datagrids. Many do re-queries against the dB ala Fritz Onion. I am trying to leverage the Dataview....
4
1695
by: Richard | last post by:
When i try sorting in the database, it sorts the numbers: 0 1 102 2 304 305 4 etc....
0
1821
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...
4
25684
by: Hushpappy | last post by:
Hello, I'm trying to sort a dataset, for some reason, when i use the writeXml of the dataset obeject I don't see any change. i'm trying to put the view into a dataview and then sort it but...
5
5964
by: Cindy Lee | last post by:
I'm getting my data from an XML file. The data binds fine, but I can't sort on it. Do I have to do anything special? I have enabled sorting on my grid view. Autogenerate columns is off, and I...
4
11125
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: Dim ReportDS As DataSet = New DataSet Dim...
0
2057
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
2
1356
by: mahesh123 | last post by:
Hi, I am using gridview in my form and binded the gridview with object datasource.I am trying to implement sorting for my grid view and i am getting following error.i am using asp.net with VB ...
0
7224
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
7323
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
7379
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...
1
7038
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
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.