?
Solved

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

Posted on 2007-03-23
6
Medium Priority
?
236 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 2000 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
Independent Software Vendors: 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

Technology Partners: 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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 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