dcsimg
Results 1 to 6 of 6

Thread: [RESOLVED] Problems sorting textbox numbers

  1. #1

    Thread Starter
    Fanatic Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    783

    Resolved [RESOLVED] Problems sorting textbox numbers

    Hi,

    I have 2 problems for which I shall post in same thread as it may very well be related to each other.

    Problem 1:

    In my database table I have one column which is number nchar(3). What is happens in my userform is that this textbox is show "blank spaces" :

    Name:  Spaces.JPG
Views: 227
Size:  8.3 KB

    I don't think it should be like that?


    Problem 2:

    For this problem I do some research online. It is caused because the numbers is stored as text in the userform (it is the same column now as per problem 1)

    When I try to sort this in correct order this is what is happen:

    Name:  Sort order.JPG
Views: 227
Size:  10.4 KB

    The number 20 should be rigt at bottom.

    I have try to convert that textbox to integer before save to database:

    Code:
    Dim MyInteger As Integer  = Convert.ToInt32(NumberTextBox.Text)
    But to no avail.

    How can I overcome there problems please?
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,048

    Re: Problems sorting textbox numbers

    The two issues aren't directly related but they could both be solved by changing the data type in the database to something numeric, which is what should be used when storing numbers. If the database is within your control, just do that. If you can't change the database data type then post back and say so and we'll look more closely at the issues.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    783

    Re: Problems sorting textbox numbers

    Hi John,

    That solved it. Once again thank you very much for your help!!
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

  4. #4

    Thread Starter
    Fanatic Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    783

    Re: Problems sorting textbox numbers

    Quote Originally Posted by jmcilhinney View Post
    The two issues aren't directly related but they could both be solved by changing the data type in the database to something numeric, which is what should be used when storing numbers. If the database is within your control, just do that. If you can't change the database data type then post back and say so and we'll look more closely at the issues.
    Hi John,

    I know this thread is resolved, but I was thinking about this... When you say something numeric, what would you recommend? Int?
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,048

    Re: [RESOLVED] Problems sorting textbox numbers

    Given that you were using Integer in the code you posted, 'int' in SQL Server seems to be the logical choice. Even if your data can fit into a smaller data type, 32-bit numbers are the most efficient for modern PCs to deal with so that should generally be your first choice for integer values.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Fanatic Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    783

    Re: [RESOLVED] Problems sorting textbox numbers

    Quote Originally Posted by jmcilhinney View Post
    Given that you were using Integer in the code you posted, 'int' in SQL Server seems to be the logical choice. Even if your data can fit into a smaller data type, 32-bit numbers are the most efficient for modern PCs to deal with so that should generally be your first choice for integer values.
    Okay, got it!

    Thank you John
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width