473,396 Members | 2,002 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.

Sorting a dataset

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
applications that see the results as xml don't have to fiddle around
and sort it themselves later).

I have tried sorting a dataview and adding that dataview's table to
the dataset but the results don't remain sorted. The only way I can
see to do it is if I return a dataview rather than a dataset (which I
don't want to do for various reasons).

Does anyone have a solution to this problem?

Many thanks.
Jul 21 '05 #1
11 16342
Hi Nikki,

I think the best thing to do is to use a dataview to sort and than use that
to make a new dataset by going through that dataview row by row.

What you need probably are
dataset.clone
datatable.importrow

(I am not sure if you can use the last one however I think that you can try
it).

I hope this helps?

Cor
Jul 21 '05 #2
I do this in VB.net by creating a datatable as a copy of the dataset then clear the dataset and merge the datatable back into the (cleared) dataset using the select command which allows filtering and sorting. BUT, once you update any data back to a database, the sort is lost, the database is nothing more than a sacck of nuts (data). If this is heading in the right path I can add some code to the discussion.
Hope it helps, John

"Nikki" wrote:
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
applications that see the results as xml don't have to fiddle around
and sort it themselves later).

I have tried sorting a dataview and adding that dataview's table to
the dataset but the results don't remain sorted. The only way I can
see to do it is if I return a dataview rather than a dataset (which I
don't want to do for various reasons).

Does anyone have a solution to this problem?

Many thanks.

Jul 21 '05 #3
Nikki,
I would do the sort on the database before filling the DataTable (an Order
By on your Select statement).

Alternatively you may try setting the primary key of the DataTable to the
sort order you want. I don't remember if that makes a difference or not...

Hope this helps
Jay
"Nikki" <ni*****@talk21.com> wrote in message
news:8d**************************@posting.google.c om...
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
applications that see the results as xml don't have to fiddle around
and sort it themselves later).

I have tried sorting a dataview and adding that dataview's table to
the dataset but the results don't remain sorted. The only way I can
see to do it is if I return a dataview rather than a dataset (which I
don't want to do for various reasons).

Does anyone have a solution to this problem?

Many thanks.

Jul 21 '05 #4
>Is it possible to sort a dataset rather than a dataview?

No - a DataSet is a collection of DataTables - you can't sort the
DataSet - what on??

Also, if ever possible, try to get the data in the right sort order
right from the beginning, e.g. add a "ORDER BY" statement to your SQL
query or stored procedure to safe yourself from having to sort the
data after it's been retrieved.

If you can't do that, then you'll need to use a DataView - the
DataTable inside a DataSet doesn't have any concept of "sort order"
per se.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Jul 21 '05 #5
Hi Marc,

The problem as Niki described is a very normal situation. He needs a
standalone dataset used on the client by instance using a webservice.

A way can be to collect it using an select with an order by.

However when there is needed after that some additions than that is
impossible.

Than the method I described using a dataview (or a sorted table or icomparer
or whatever but I would take the dataview) and use that to create a new
dataset by cloning the table(s) and fill it again is for me the way to go.

This because you wrote.
No - a DataSet is a collection of DataTables - you can't sort the
DataSet - what on??

Cor
Jul 21 '05 #6
>A way can be to collect it using an select with an order by.

That's what I'm trying to say - if ever possible, do it right from the
beginning - don't just return an unsorted list of data, and then sort
if on the client, if the server could have returned it in the right
sort order already!
However when there is needed after that some additions than that is
impossible.


Yes, agreed - but again - you CANNOT sort a DataSet - you can maybe
sort a DataTable. But even then - I don't like the idea of
duplicating, cloning etc., just to get the right sort order, if the
DataView already offers that WITHOUT any need to duplicate. Duplicates
are always redundant, and redundancy in database is a big no-no.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Jul 21 '05 #7
>A way can be to collect it using an select with an order by.

That's what I'm trying to say - if ever possible, do it right from the
beginning - don't just return an unsorted list of data, and then sort
if on the client, if the server could have returned it in the right
sort order already!
However when there is needed after that some additions than that is
impossible.


Yes, agreed - but again - you CANNOT sort a DataSet - you can maybe
sort a DataTable. But even then - I don't like the idea of
duplicating, cloning etc., just to get the right sort order, if the
DataView already offers that WITHOUT any need to duplicate. Duplicates
are always redundant, and redundancy in database is a big no-no.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Jul 21 '05 #8
Marc,

I did not say that I disagree, however how you do what you wrote when a
sorted disconnected dataset is needed at the clientside by instance because
it is readed with loadXML or something like that and the situation is that
before that some not database rows has to be added.

In most other situations we agree.

And do not take the subject to strict, I assume that the OP asked with
sorting a dataset sorting the tables and probably he has only one table in
it. Where I was as well writing about the table(s) contained in the dataset.

Cor
A way can be to collect it using an select with an order by.


That's what I'm trying to say - if ever possible, do it right from the
beginning - don't just return an unsorted list of data, and then sort
if on the client, if the server could have returned it in the right
sort order already!
However when there is needed after that some additions than that is
impossible.


Yes, agreed - but again - you CANNOT sort a DataSet - you can maybe
sort a DataTable. But even then - I don't like the idea of
duplicating, cloning etc., just to get the right sort order, if the
DataView already offers that WITHOUT any need to duplicate. Duplicates
are always redundant, and redundancy in database is a big no-no.

Marc

Jul 21 '05 #9
Marc,

I did not say that I disagree, however how you do what you wrote when a
sorted disconnected dataset is needed at the clientside by instance because
it is readed with loadXML or something like that and the situation is that
before that some not database rows has to be added.

In most other situations we agree.

And do not take the subject to strict, I assume that the OP asked with
sorting a dataset sorting the tables and probably he has only one table in
it. Where I was as well writing about the table(s) contained in the dataset.

Cor
A way can be to collect it using an select with an order by.


That's what I'm trying to say - if ever possible, do it right from the
beginning - don't just return an unsorted list of data, and then sort
if on the client, if the server could have returned it in the right
sort order already!
However when there is needed after that some additions than that is
impossible.


Yes, agreed - but again - you CANNOT sort a DataSet - you can maybe
sort a DataTable. But even then - I don't like the idea of
duplicating, cloning etc., just to get the right sort order, if the
DataView already offers that WITHOUT any need to duplicate. Duplicates
are always redundant, and redundancy in database is a big no-no.

Marc

Jul 21 '05 #10
>And do not take the subject to strict, I assume that the OP asked with
sorting a dataset sorting the tables and probably he has only one table in
it. Where I was as well writing about the table(s) contained in the dataset.


Oh, I imagined as much, but I think it's important to be very clear
about the terminology, in order to really understand what's happening.
The fact Microsoft choose to call a collection of tables and relations
a "DataSet" is a bit unfortunate, since that's really a very generic
term, but that's the way it is in the .NETframework, and you need to
be careful to use the appropriate terms, in order to minimize
confusion and chaos ;-)

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Jul 21 '05 #11
>And do not take the subject to strict, I assume that the OP asked with
sorting a dataset sorting the tables and probably he has only one table in
it. Where I was as well writing about the table(s) contained in the dataset.


Oh, I imagined as much, but I think it's important to be very clear
about the terminology, in order to really understand what's happening.
The fact Microsoft choose to call a collection of tables and relations
a "DataSet" is a bit unfortunate, since that's really a very generic
term, but that's the way it is in the .NETframework, and you need to
be careful to use the appropriate terms, in order to minimize
confusion and chaos ;-)

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Jul 21 '05 #12

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

Similar topics

1
by: Dave S | last post by:
Hi, I'm using a datagrid to display contents of a dataset and I've set the datagrid to allow paging and sorting. Rather than re-retrieve from the DB, I store the original dataset in a Session...
4
by: Deepa | last post by:
I have a dataset which am trying to sort by 3 specific columns. I am not making any connection to the database to get the dataset. I have the raw dataset already. What i tried doing was to create...
4
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...
4
by: Mark Travis | last post by:
Hi all, I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid. To Digress ======= Development information about the page is as follows 1....
1
by: Slonocode | last post by:
I have a form with some textboxes, checkboxes, and comboboxes that are databound to the "Packages" table in a dataset. For Example: Me.txtFirstName.DataBindings.Add(New Binding("Text", DS,...
8
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
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
parshupooja
by: parshupooja | last post by:
Hey All, I have DataSet. I want to sort it. Can anyone help. I tried Smthing looking for Sort method but Don't see it. Thanks
1
by: Aeric | last post by:
I have read the following topic: sorting dataset and I am facing the same issue. I am designing a report. I have fill a dataset with the results from a query. From the results, I used to set...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.