472,333 Members | 1,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 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 16218
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...
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...
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...
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 =======...
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:...
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...
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...
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.