Sql sorting problem...

Discussion in 'Questions (Windows Mobile)' started by belotrei, Jun 3, 2007.

  1. belotrei

    belotrei Member

    Hmm, hope this is not a stupid question.. but i've got lost (again)... :sign0161:

    i want to order number in sql database :
    numberid in row : (data)
    1
    2
    3
    4
    5
    6
    ... and so on... 1500

    cmd.CommandText = "select numberid from master order by numberid"
    ' and see the result :
    cmd.ExecuteTable("table1", rowstoload)

    but why in the table it becomes :
    1
    10
    100
    1000
    1001
    1002
    1003
    1004
    1005
    .... and so on...

    How can I fix this ?

    Thanks.

    PS: i need to use "order" command of sql function because i want to use this code:
    cmd.CommandText = "select numberid from master order by numberid"
    ' and see the result :
    cmd.ExecuteTable("table1", rowstoload)
    'numberid has been loaded to tablecontrol (but not organized)
    .....
    ....
    new control, lets say a button control :
    cmd.CommandText = "select data, numberid from master where numberid <= '" & table1.Cell("numberid", xxx) & "'
    cmd.ExecuteTable("table1", RowsToLoad)

    ' or >= from numberid

    (Yeah that's the code from dzt's project.)

    So it will chaos if the sorting of sql is not right, because the table control will be filled from sql.

    Sorry if the code / my explanation makes you a little bit confused, i haven't take a sleep for 3 days... Very curious and exciting with this project..
     
  2. dzt

    dzt Active Member Licensed User

    Sorting depends on fields type (TEXT or NUMERIC).
    I can see that in your case NUMBERID is TEXT so in a TEXT (or string) field "2" is greater than "11" ("B" in alphabetical order is after "AA").

    To have your query sorted right you should define field NUMBERID NUMERIC, or keep if TEXT and fill it with 0s.

    0001
    0002
    .
    .
    .
    0011
    .
    .
    .
    0021
    .
    .
    .
     
  3. belotrei

    belotrei Member

    Thank you so much! Your solutions are working GREAT, dzt! How lucky i am can found this forum..
    The guys here are so helpful and KIND. (and genius too... :) )

    Dzt, i think you're a master in sql database.. Actually, does your job have relationship with software/database programming?

    Cheers.
     
  4. dzt

    dzt Active Member Licensed User

    Your are welcome belotrei,

    My job is absolutely relevant.

    Sleep is incompatible with app development as you mentioned in other way above... :)
     
  5. belotrei

    belotrei Member

    Hahaha... btw, thank you so much dzt! Finally i can sleep peacefully now... after got the vErY helpful help from you...

    :sign0188:

    Don't get bored with my stupid question, dzt. I've just learned sql recently... :sign0060:
     
Loading...