Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sort DataSet with multiple column names

Posted on 2004-08-16
5
Medium Priority
?
932 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 1000 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 1000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

927 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