DataView.Sort not sorting

G

Guest

Hello,

Can anyone tell me what is wrong with the following? I am
trying to sort a table, then return it as the dataset.
The dataset ds1 is returned, but is the same as the
orignal, meaning that the sort did not take place.

Thanks,

David

(existing dataset ds passed in to method)
....
DataView dv = ds.Tables[0].DefaultView;
dv.ApplyDefaultSort = false;
dv.Sort = "EVENT_DATE, LOCATION_CODE desc";
DataTable dt = dv.Table.Copy();

DataSet ds1 = new DataSet(dv.Table.TableName);
ds1.Tables.Add(dt);
return ds1
 
T

touf

How do you use your table, (datagrid, ....) ?
do you use dt.rows or dt.defaultview ???

I think that the sort in vb.net is applyed to the defaultView not the table,
so you've to use the defaultview
 
C

Chris Botha

The sort is on the DataView, not the DataTable, the order of the rows in the
DataTable stays the same after the sort. After the sort, you must iterate
through the DataView to get them sorted.
 

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

Top