Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DataView sorting - appears to sort but the order is incorrect

Posted on 2007-11-25
5
Medium Priority
?
757 Views
Last Modified: 2013-11-26
Hi Guys,

I am sorting a dataview which is gained from the table of a dataset I have created (not data straight from a database).  I have some code that at first seems to work, ie the data switches order, but the sort is incorrect.  For example if i had the data 1,4,66,2,3 the data could come back for example as 66,4,2,1,3!!

I am thoroughly confused by this.  The column names are all correct etc...  

Please help if you have any thoughts or have seen this before.

Thanks in advance, Phil
Sub sortGrid(ByVal colName As String)
 
        'get the dataset from the session item
        Dim dsCurrent As New DataSet
        dsCurrent = Session.Item("data")
 
	'create a dataview to manipulate the data
 	Dim dataView As New DataView(dsCurrent.Tables(0))
	
	'create the sort
        dataView.Sort = colName & " DESC"
 
        GridView1.DataSource = dataView
        GridView1.DataBind()
       
End Sub

Open in new window

0
Comment
Question by:Artform04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20345534
What is the data type of the field that you are sorting?

Have you checked that you are actually sorting on the field that you think you are? It looks like you are soring on something else.

By the way, you are creating a DataSet object that you just throw away.

Dim dsCurrent As New DataSet
dsCurrent = Session.Item("data")

should be:

Dim dsCurrent As DataSet
dsCurrent = Session.Item("data")
0
 
LVL 1

Author Comment

by:Artform04
ID: 20345617
Ill show you how the dataset is created, the code is below.  The data stored in it is an amalgamation of a number of lengthy database queries that is then analysed.  How can i cast the type of the data?

Thanks, Phil
 'create the results table
        Dim results As New DataSet
        With results
            .Tables.Add()
            With .Tables(0)
                .Columns.Add("Device")
                .Columns.Add("Journeys")
                .Columns.Add("Avg")
                .Columns.Add("Min")
                .Columns.Add("Max")
                .Columns.Add("Pickups")
                .Columns.Add("Hits")
            End With
        End With
 
 
 
'BUNCH OF ANALYSIS CODE HERE... 
 
 
 
 'add a new row to the final results
            results.Tables(0).Rows.Add()
            With results.Tables(0).Rows(results.Tables(0).Rows.Count - 1)
                .Item(0) = deviceModel
                .Item(1) = CInt(count)
                .Item(2) = CInt(average)
                .Item(3) = CInt(min)
                .Item(4) = CInt(max)
 
                Dim ds2 As New DataSet
                ds2 = objDb.getPickupAndHitsForPhone(deviceModel, unitLinkId, dateFrom, dateTo)
 
                .Item(5) = CInt(ds2.Tables(0).Rows(0).Item(0))
                .Item(6) = CInt(ds2.Tables(0).Rows(0).Item(1))
            End With

Open in new window

0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 1400 total points
ID: 20345644
As you are not specifying any data type for the columns in the data table, they are all strings. Specify the data type for the columns that should be integers:
System.Type typeInt = System.Type.GetType("System.Int32");
With .Tables(0)
   .Columns.Add("Device")
   .Columns.Add("Journeys", typeInt)
   .Columns.Add("Avg", typeInt)
   .Columns.Add("Min", typeInt)
   .Columns.Add("Max", typeInt)
   .Columns.Add("Pickups", typeInt)
   .Columns.Add("Hits", typeInt)
End With

Open in new window

0
 
LVL 1

Author Comment

by:Artform04
ID: 20358033
thanks, that works.  But instead of "typeInt" i had to put  "type.getType("system.int32")"
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20358140
The typeInt variable is declared on line 1 in the code snippet, so that you don't have to call GetType repeatedly.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
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.…

610 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