DataView.Sort not sorting

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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.
 
Back
Top