Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
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
 
Old May 18th, 2006, 03:54 PM
Authorized User
 
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?


 
Old May 18th, 2006, 03:59 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
 
Old May 18th, 2006, 04:05 PM
Authorized User
 
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old May 18th, 2006, 04:14 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
 
Old May 18th, 2006, 04:56 PM
Authorized User
 
Join Date: Jul 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old May 18th, 2006, 05:11 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Data sorting dilipv .NET Framework 2.0 1 March 10th, 2008 09:19 AM
DataGridView - Sorting Data pencilneck Visual Studio 2005 0 October 23rd, 2007 04:35 PM
sorting retrieved data don baroo Classic ASP Basics 2 November 23rd, 2004 08:31 AM
Sorting Data seidici Excel VBA 2 May 21st, 2004 02:24 PM
Sorting in Data Grid matt.fields ASP.NET 1.0 and 1.1 Basics 0 October 21st, 2003 12:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.