Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 29th, 2003, 12:48 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default Dataset does not get sorted correctly

Hi there,

I have a small XML file that I want to read into a dataset. The XML file contains a sortorder node and I'd like to sort the data in the XML file using that node.

Funny thing is that the data in the DataSet does not get sorted correctly. Here's the XML file:

<?xml version="1.0" encoding="utf-8" ?>
<mylinks>
<mylink>
    <url>Item 1</url>
    <name>Name of Item 1</name>
    <sortorder>10</sortorder>
</mylink>
<mylink>
    <url>Item 2</url>
    <name>Name of Item 2</name>
    <sortorder>20</sortorder>
</mylink>
</mylinks>

and here's the VB code I am using:
Code:
Dim MyDataSet As New DataSet
MyDataSet.ReadXml("links.xml")

Dim MyDataView As DataView = MyDataSet.Tables(0).DefaultView
MyDataView.Sort = "sortorder DESC"
For Each MyDataRow As DataRow In MyDataView.Table.Rows
    MessageBox.Show("Item is " & MyDataRow(0))
Next
DataGrid1.DataSource = MyDataView
The weird thing is that the For Each loop does *not* return the items in the requested order. That is, Item 1 comes first, then Item 2.

However, the DataGrid *does* display the data in the correct order.

Is there anything I should do to retrieve the data from the DataSet in the right order using For Each or For? I know it's in there in the right order, because the DataGrid can display the data correctly....

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #2 (permalink)  
Old December 29th, 2003, 03:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

I believe the 'Table' property of the DataView refers to the underlying data table, which is not affected by the the 'sort' property. I think you want to use a DataRowView as, e.g.:
Code:
    For Each MyDataRow As DataRowView In MyDataView
        MessageBox.Show("Item is " & CStr(MyDataRow.Item(0)))
    Next
which does iterate in the correct sort order.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
Reply With Quote
  #3 (permalink)  
Old December 29th, 2003, 04:49 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Jeff,

Thanks a lot. That was exactly what I was looking for.

Cheers,


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Position of sorted nodes tall rog XSLT 5 July 9th, 2007 05:59 PM
How to get least value numbers in a sorted array? ashokparchuri Other Programming Languages 3 December 5th, 2006 09:25 AM
Urgent Issue to be sorted out mike_remember ASP.NET 1.0 and 1.1 Professional 5 November 1st, 2006 10:52 AM
sorted table crmpicco Javascript How-To 0 March 17th, 2005 10:29 AM
Search in a sorted list yajleejnus Classic ASP Basics 0 June 11th, 2003 04:00 PM



All times are GMT -4. The time now is 03:08 PM.


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