Solved

sort DataSet with multiple column names

Posted on 2004-08-16
5
910 Views
Last Modified: 2010-08-05
Hi I have one data table and I have usercontrol to return dataset of data table.
Because I have multiple columns in the data table , I like to sort by
"column1(String), column2(String), column3(DateTime) DESC" , and then return dataset.

Here is my code.
//create disk data table already, diskDT
//ds.Tables.Add(diskDT); //assign to dataset as a return later
string sortstr = "PatientID,ShotDate,ShotProc,FileName DESC";
DataView dv = new DataView();
dv = diskDT.DefaultView;
dv.Sort = sortstr;
ds = dv.Table.DataSet;
return ds

However, data set shows the original and did not sort it out.
How can I get the sort result to dataset?

 
0
Comment
Question by:young_nacs
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
vijay_a73 earned 250 total points
ID: 11813552
Try this..

string sortstr = "PatientID,ShotDate,ShotProc,FileName DESC";
diskDT.DefaultView.Sort = sortstr;
return diskDT;
0
 
LVL 2

Expert Comment

by:vijay_a73
ID: 11813596
hey..

its return ds and not diskDT.
0
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 250 total points
ID: 11816124
Hi there,
DataSet does NOT retain sorting. Not even a Table. We can sort only a VIEW. so, instead of returning DataSet/Table, return the sorted VIEW.

If you want the sorted records in the DataSet/Table, change your Sql query for sorted selection. Something like..
"SELECT * FROM Emp ORDER BY EmpID,EmpName, Dept DESC"  
-Baan
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question