 |
| ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application . |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 18th, 2006, 03:54 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorting data in a DataSet
I have a DataSet with a table that has data in it. I am using the DataViewManager to sort the LastName column in a table. The DataSet only contains one table named âTableâ. Here is the code that I use to sort the table:
// Get Data
DataSet docsSelected = Document.FindByCClipIDs(currentUser, originalFiles.Split(';'));
// Attempt to sort with DataViewManager
DataViewManager myDVM = new DataViewManager(docsSelected);
myDVM.DataViewSettings["Table"].Sort = "LastName ASC";
However, when I go look inside the table in the DataSet, the LastName column has not been sorted. Nothing appears to happen. Here is the code that I check the data:
// read the dataset row by row
for (int i = 0; i < docsSelected.Tables[0].Rows.Count; i++)
{
DataRow foundRow = docsSelected.Tables[0].Rows[i];
strTitle = foundRow["Title"].ToString();
strCaseNumber = foundRow["CaseNumber"].ToString();
strLastName = foundRow["LastName"].ToString();
strCclipID = foundRow["CclipID"].ToString();
strTitle = strTitle + ", " + strLastName + ", " + strCaseNumber;
}
I like to keep the DataSet and sort the table in there and pass it around to other components with the data sorted. How do I tell if the DataSet is really sorted?
|
|

May 18th, 2006, 03:59 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
I had the exact same question a while ago, and it was answered here: http://p2p.wrox.com/topic.asp?TOPIC_ID=8065
The trick is loop through the DataView, with DataRowViews, and not through the table, which remains unsorted.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

May 18th, 2006, 04:05 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar.
Is the DataSet really sorted? Or, is the DataView really sorted? I need to keep using the DataSet and have the data in the DataSet sorted. Do you have to convert the DataView to a DataSet?
|
|

May 18th, 2006, 04:14 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Asa far as I know, the tables in the DataSet remain unsorted (that's what you found out).
I think you can see the DataView as a View in SQL Server: it's just a view on other data. Tables are unsorted by design; but a view targeting that table can be sorted. The same seems to apply to a DataSet: the DataTable is unsorted, but you can get a sorted view of the data with a DataView.
Does that help?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

May 18th, 2006, 04:56 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar. I understand.
So, looks like I will have to use the DataView and sort that. Plus, change some methods to expect the DataView instead of the DataSet. Or, I can sort the data on the SQL Server, which could be easier.
Paul
|
|

May 18th, 2006, 05:11 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yeah, sorting at the data source is probably the easiest and fastest thing to do...
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|
 |