Hi,
I have a DataSet, returned by a stored procudure, which has only on
DataTable. At this step there is no sort in DataTable. Is there is a way I
can do to sort DataRows in this DataTable (not from select statement of sql
query) in memory?
Thanks

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy

Re: In memory sort a DataTable in DataSet by Nicholas

Nicholas
Tue Sep 07 12:08:16 CDT 2004

Hardy,

Absolutely. Create a new instance of a DataView class, and then pass
the DataTable you want to sort to the DataView. Once you do that, you can
set the Sort property to the fields that you want to sort the DataTable by.

Then, you would access the rows through the data view, not through the
table, and you will see them in order.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"Hardy Wang" <hardywang@hotmail.com> wrote in message
news:OeRsSzPlEHA.3988@tk2msftngp13.phx.gbl...
> Hi,
> I have a DataSet, returned by a stored procudure, which has only on
> DataTable. At this step there is no sort in DataTable. Is there is a way I
> can do to sort DataRows in this DataTable (not from select statement of
> sql query) in memory?
> Thanks
>
> --
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
>



Re: In memory sort a DataTable in DataSet by Miha

Miha
Tue Sep 07 12:27:04 CDT 2004

Hi Hardy,

Just an addition to Nicholas' post.
You could use DataTable.DefaultView (as a DataView instance Nicholas
mentioned) which is also used as a datasource when the DataTable is bound.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Hardy Wang" <hardywang@hotmail.com> wrote in message
news:OeRsSzPlEHA.3988@tk2msftngp13.phx.gbl...
> Hi,
> I have a DataSet, returned by a stored procudure, which has only on
> DataTable. At this step there is no sort in DataTable. Is there is a way I
> can do to sort DataRows in this DataTable (not from select statement of
> sql query) in memory?
> Thanks
>
> --
> WWW: http://hardywang.1accesshost.com
> ICQ: 3359839
> yours Hardy
>



Re: In memory sort a DataTable in DataSet by Cor

Cor
Tue Sep 07 12:41:31 CDT 2004

Hardy,

When you want see a datatable in a special sequence you can use the dataview
to view the datatable in sorted order.

When you want to sort the datatable, you can clone that table and than loop
thru the dataview row by row and add the rows to that new datatable, which
can in a generic way because the rows and the items from the dataview are
equal on the datatable (when you do not set a dataview.rowfilter).

I hope this helps?

Cor

"Hardy Wang"
> Hi,
> I have a DataSet, returned by a stored procudure, which has only on
> DataTable. At this step there is no sort in DataTable. Is there is a way I
> can do to sort DataRows in this DataTable (not from select statement of
sql
> query) in memory?
> Thanks
>



Re: In memory sort a DataTable in DataSet by Miha

Miha
Tue Sep 07 13:54:37 CDT 2004



> When you want to sort the datatable, you can clone that table and than
> loop
> thru the dataview row by row and add the rows to that new datatable, which
> can in a generic way because the rows and the items from the dataview are
> equal on the datatable (when you do not set a dataview.rowfilter).

Hi Cor,

A note:
Although this is technically correct, there is no much sense in sorting the
datatable (not that I am implying that you think otherwise).
Just my opinion :-)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com



Re: In memory sort a DataTable in DataSet by Cor

Cor
Tue Sep 07 14:09:22 CDT 2004

Miha,
>
> Hi Cor,
>
> A note:
> Although this is technically correct, there is no much sense in sorting
the
> datatable (not that I am implying that you think otherwise).
> Just my opinion :-)
>
I was expecting you would write this.

In common use there is no reason, however there is at least one, when you
want to export a dataset to a XML file on disk or whatever and use that in a
loadXML(doc) or whatever to process even in not dotNet environments
sequentially.

Can we make it 1:1 or can you make it 2:0

(Although I have the same meaning as you of course, it is for every day
learning so loosing is winning)

:-)

Cor



Re: In memory sort a DataTable in DataSet by Miha

Miha
Tue Sep 07 15:47:41 CDT 2004


"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:uUFxq4QlEHA.2500@TK2MSFTNGP09.phx.gbl...
> Miha,
>>
>> Hi Cor,
>>
>> A note:
>> Although this is technically correct, there is no much sense in sorting
> the
>> datatable (not that I am implying that you think otherwise).
>> Just my opinion :-)
>>
> I was expecting you would write this.
>
> In common use there is no reason, however there is at least one, when you
> want to export a dataset to a XML file on disk or whatever and use that in
> a
> loadXML(doc) or whatever to process even in not dotNet environments
> sequentially.

I would preffer using XPath sorting for this purpose. :-)


--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com