DataSet sorting

B

Björn

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
 
A

avnrao

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.
 
B

Björn

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 said:
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 said:
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
 
A

avnrao

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 said:
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 said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,129
Latest member
FastBurnketo
Top