Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Database > ADO.NET

ADO.NET Anything regarding DataAdapters, DataReaders, DataSets, etc.

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2009, 10:19 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jul 2009
Age: 29
Posts: 2
Reputation: 0
Ylva D is on a distinguished programming path ahead
Lightbulb Does DataView.ToTable() keep a descending sort order?

Hi everyone!

I have a problem with sorting a DataTable. I'm using DataView.Sort and then DataView.ToTable() to get the sorted table. Then I go through the table row by row and create nodes in a TreeView which is shown in a desktop application.

My problem is that I can sort the data in ascending order and it is shown in the TreeView in a correct way, but when I use the same sort mechanism but just change the order to descending it doesn't work.

But maybe the problem lies in the DataView.ToTable function. Does this keep a descending order or do I have to fix this myself when I create nodes in my TreeView by going through the DataRows in reverse order?

Hoping someone knows this.
Thanks in advance,

/Ylva
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-02-2009, 10:40 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,322
Reputation: 1315
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

My test show both sort orders are preserved.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-02-2009, 11:25 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jul 2009
Age: 29
Posts: 2
Reputation: 0
Ylva D is on a distinguished programming path ahead
Default

Ok. Then something must be really strange about my code because when I step through my sorting function I see that the sort direction is "DESC" and then I run the ToTable() function but when I step through the resulting table like this..

Code:
For r As Integer = 0 To dataTable.Rows.Count - 1

            Dim row As DataRow = dataTable.Rows(r)
            ......
Next
...I see that the table still is sorted in an ascending direction.

What could be the explanation for this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-04-2009, 6:07 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,442
Reputation: 807
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

Why do you care about the order of rows in the table? Why not just use the DataView as the data source for your tree view; the rows are coming out in order.

Tables are not suposedto be sortd/have order imposed/relied upon. If you want rows out in a certain order, pull them out of the view, because the view;s job is to perform the ordering

In MVC concept, table is the M and, not the V (view is the V) so by trying to get an M to behave as a V youre using the wrong tool for the job
__________________
DW1 DW2 DW3 DW4 DNU PQ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
dataview, desc, sort, totable


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 8:11 PM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.