By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

DataSet sorting

P: n/a
Hi List

I´m generating a DataSet using a simple sql select statement. Now my DataSet
has several rows with columns(ID,NAME,CAPTION)

Now I want to sort the DataSet for column Caption. I can´t use sql "order
by" because the caption field is of Sqltype text.
So I wanted to use the DataView object sort order.
----sample code--------------------------
DataView sortView = this.sqlResultDS.Tables[0].DefaultView;//new
DataView(this.sqlResultDS.Tables[0]);
sortView.AllowEdit = true;

sortView.Sort = "CAPTION DESC";//sort data
this.sqlResultDS.Tables.RemoveAt(0);//remove old unsorted data

this.sqlResultDS.Tables.Add(sortView.Table);//add new sorted data (does not
function)

----------------------------------------------------------------------------
----------------

Something is wrong with my Code, the data is not sorted.

Any ideas???

regards

Björn
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
this.sqlResultDS.Tables.RemoveAt(0);//remove old unsorted data
this line removes the table...

this.sqlResultDS.Tables.Add(sortView.Table);//add new sorted data (does not
function)
this line again tries to add the same table.. when you sort using sortview,
i dont think the underlying table gets modified. when you bind the DataView
to some control, only then the actual sorting occurs. so try binding your
DataView to some control and check if its working.

Av.
"Björn" <pr********@gmx.net> wrote in message
news:Oe*************@TK2MSFTNGP12.phx.gbl...
Hi List

I´m generating a DataSet using a simple sql select statement. Now my
DataSet
has several rows with columns(ID,NAME,CAPTION)

Now I want to sort the DataSet for column Caption. I can´t use sql "order
by" because the caption field is of Sqltype text.
So I wanted to use the DataView object sort order.
----sample code--------------------------
DataView sortView = this.sqlResultDS.Tables[0].DefaultView;//new
DataView(this.sqlResultDS.Tables[0]);
sortView.AllowEdit = true;

sortView.Sort = "CAPTION DESC";//sort data
this.sqlResultDS.Tables.RemoveAt(0);//remove old unsorted data

this.sqlResultDS.Tables.Add(sortView.Table);//add new sorted data (does
not
function)

----------------------------------------------------------------------------
----------------

Something is wrong with my Code, the data is not sorted.

Any ideas???

regards

Björn

Nov 18 '05 #2

P: n/a
Hey

Thanks for your answer.
Because I´m working with dataset in a class project and not a web project I
can´t bind the DataView to an Aspnet Control.
So this means I have to implement the sort for the dataset on my own? right?

regards

Björn

"avnrao" <av*@newsgroups.com> schrieb im Newsbeitrag
news:#0**************@TK2MSFTNGP12.phx.gbl...
this.sqlResultDS.Tables.RemoveAt(0);//remove old unsorted data
this line removes the table...

this.sqlResultDS.Tables.Add(sortView.Table);//add new sorted data (does not function)
this line again tries to add the same table.. when you sort using sortview, i dont think the underlying table gets modified. when you bind the DataView to some control, only then the actual sorting occurs. so try binding your
DataView to some control and check if its working.

Av.
"Björn" <pr********@gmx.net> wrote in message
news:Oe*************@TK2MSFTNGP12.phx.gbl...
Hi List

I´m generating a DataSet using a simple sql select statement. Now my
DataSet
has several rows with columns(ID,NAME,CAPTION)

Now I want to sort the DataSet for column Caption. I can´t use sql "order by" because the caption field is of Sqltype text.
So I wanted to use the DataView object sort order.
----sample code--------------------------
DataView sortView = this.sqlResultDS.Tables[0].DefaultView;//new
DataView(this.sqlResultDS.Tables[0]);
sortView.AllowEdit = true;

sortView.Sort = "CAPTION DESC";//sort data
this.sqlResultDS.Tables.RemoveAt(0);//remove old unsorted data

this.sqlResultDS.Tables.Add(sortView.Table);//add new sorted data (does
not
function)


--------------------------------------------------------------------------

--
----------------

Something is wrong with my Code, the data is not sorted.

Any ideas???

regards

Björn


Nov 18 '05 #3

P: n/a
if you have to sort the values and just use them in the class as sorted, use
this code..

DataView sorted = GetDataView();
System.Collections.IEnumerator ienum = sorted.GetEnumerator();
int iLen = sorted.Table.Rows.Count;
DataRowView drv;
while(ienum.MoveNext())
{
drv = (DataRowView)ienum.Current;
lstBox.Items.Add(new ListItem(drv.Row["ProgramName"].ToString())); i
just added the value in the list box.
}

hth,
Av.
"Björn" <pr********@gmx.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hey

Thanks for your answer.
Because I´m working with dataset in a class project and not a web project
I
can´t bind the DataView to an Aspnet Control.
So this means I have to implement the sort for the dataset on my own?
right?

regards

Björn

"avnrao" <av*@newsgroups.com> schrieb im Newsbeitrag
news:#0**************@TK2MSFTNGP12.phx.gbl...
this.sqlResultDS.Tables.RemoveAt(0);//remove old unsorted data
this line removes the table...

this.sqlResultDS.Tables.Add(sortView.Table);//add new sorted data (does

not
function)
this line again tries to add the same table.. when you sort using

sortview,
i dont think the underlying table gets modified. when you bind the

DataView
to some control, only then the actual sorting occurs. so try binding your
DataView to some control and check if its working.

Av.
"Björn" <pr********@gmx.net> wrote in message
news:Oe*************@TK2MSFTNGP12.phx.gbl...
> Hi List
>
> I´m generating a DataSet using a simple sql select statement. Now my
> DataSet
> has several rows with columns(ID,NAME,CAPTION)
>
> Now I want to sort the DataSet for column Caption. I can´t use sql "order > by" because the caption field is of Sqltype text.
> So I wanted to use the DataView object sort order.
> ----sample code--------------------------
> DataView sortView = this.sqlResultDS.Tables[0].DefaultView;//new
> DataView(this.sqlResultDS.Tables[0]);
> sortView.AllowEdit = true;
>
> sortView.Sort = "CAPTION DESC";//sort data
>
>
> this.sqlResultDS.Tables.RemoveAt(0);//remove old unsorted data
>
> this.sqlResultDS.Tables.Add(sortView.Table);//add new sorted data (does
> not
> function)
>


--------------------------------------------------------------------------

--
> ----------------
>
> Something is wrong with my Code, the data is not sorted.
>
> Any ideas???
>
> regards
>
>
>
> Björn
>
>



Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.