Solved

How can I get Text values that appear as numbers sort in 'numeric' order in a datagrid?

Posted on 2007-03-23
6
235 Views
Last Modified: 2010-04-23
I have database columns that are defined as Text. One, labeled PartID sometimes has values such as 1,2,3...etc. The problem is when I want to sort in a d dataGrid, it will  sort like 1,11,12,2,3,32,4...etc. How can I get it to sort as if they were consecutive numbers? The fielf is defined Text because more often than not, the value may be alpha in nature too. Thank you in advance for code examples.
0
Comment
Question by:IT_Steve
[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
6 Comments
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 18784692
use this

select convert(int, partId) from demo order by convert(int,partid) asc
0
 

Author Comment

by:IT_Steve
ID: 18788276
I apologize for forgetting to include I am using Access for my database.  I have not found a way to make your suggestion work. Is that for stored procedures? I will need a solution that can deal with values such as 1,2,3..,Dave's-40,SJ,... etc.
0
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 18789802
The only way to get around it is to format that field to have a leading zero if the number is between 1 and 9.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 18790803
use it like this

    Dim ds As New DataSet
    Dim da As SqlDataAdapter
    Dim sql As String
    Dim myConnection As SqlConnection
    Dim ConnStr As String = "ur connection string here"

            myConnection = New SqlConnection(ConnStr)

            sql = "select convert(int, partId), partname,partdesc,allothercolumns from demo order by convert(int,partid) asc"
            da = New SqlDataAdapter(sql, myConnection)
            da.Fill(ds, "demo")

0
 

Author Comment

by:IT_Steve
ID: 18792716
Ajaysharmaapjs -
When I try the code you suggest, I get the error: Undefined function 'Convert' in expression. I am using VB.NET 2003. Perhaps Convert is a built in method in 2005? But I was wondering how it willl behave if the partID was 'Steve'sWidget4'? Remember, some partID look numeric, 1,72,4, but many are mixed like 'Steve'sWidget4' or all alpha chars 'NinethParcel'.

Planoz -
I was hoping to avoid the 0 but may be resigned to that. I will wait awhile to see if there are other suggestions.
0
 

Author Comment

by:IT_Steve
ID: 18800070
Planoz - Your solution answered my question as asked and works. I was intrigued by Ajaysharmaapjs 's Select CONVERT(... concept but it didn't work for me.  Thank you for your ideas.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

705 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