Results 1 to 7 of 7

Thread: [RESOLVED] SQL: Select Query Results

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    18

    Resolved [RESOLVED] SQL: Select Query Results

    Hello!

    First of all let me say a big thank to all the people contributing in this forum helping us improving our VB knowledge ... Now, let me post my question!

    I have an application where number from 0 to 60 are my entries and saved into a tbl with the relevant Date of Entry. I run an SQL query, count and grouping numbers according to their frequency and date of entry and send them to a form. Up to now everything ok. What i need now....

    Assume that we have a table with the following type of records:

    1 12
    2 10
    3 22
    4 8
    5 6

    The first column is the Number Entered and the second one is the Frequency. I want to run a Select Query, Order by Ascending Order and present the results on textboxes, E.g from the above example to have 5 boxes and the relevant results. How?

    Actually I need to know how to play with the SQL query ...

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: SQL: Select Query Results

    There's nothing complex about the query. It's just something like:
    SQL Code:
    1. SELECT Column1, Column2
    2. FROM MyTable
    3. ORDER BY Column2
    Assuming you don't know how many rows there will be, you'd have to get the record count and then create that many TextBoxes and place them on your form in code. If you know the number of records beforehand then you can add the TextBoxes at design time.

    Either way, I'd suggest adding the TextBoxes to an array and then using a For loop to loop through the TextBoxes and records simultaneously, populating the TextBoxes as you go. We can't really tell you how to do that because we don't know what language your app is written in. I guess it's VB but is that VB6 or VB.NET?
    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
    Junior Member
    Join Date
    Jul 2009
    Posts
    18

    Re: SQL: Select Query Results

    Quote Originally Posted by jmcilhinney View Post
    There's nothing complex about the query. It's just something like:
    SQL Code:
    1. SELECT Column1, Column2
    2. FROM MyTable
    3. ORDER BY Column2
    Assuming you don't know how many rows there will be, you'd have to get the record count and then create that many TextBoxes and place them on your form in code. If you know the number of records beforehand then you can add the TextBoxes at design time.

    Either way, I'd suggest adding the TextBoxes to an array and then using a For loop to loop through the TextBoxes and records simultaneously, populating the TextBoxes as you go. We can't really tell you how to do that because we don't know what language your app is written in. I guess it's VB but is that VB6 or VB.NET?
    Well It is VB6. But in any case i do not have problem with the query but... assume that I select by order (e.g ascending one). How can I put in first textbox the number ordered first, then second etc?

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: SQL: Select Query Results

    Lable1 = rs.Fields(0).Value
    TextBox1.rs.Fields(1).Value
    rs.moveNext
    .....
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    18

    Re: SQL: Select Query Results

    Quote Originally Posted by GaryMazzone View Post
    Lable1 = rs.Fields(0).Value
    TextBox1.rs.Fields(1).Value
    rs.moveNext
    .....
    thanks a lot. I will try and confirm if it is ok. But many thanks in any case

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    18

    Resolved Re: SQL: Select Query Results

    Thanks a lot... it works

    Stefanos

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL: Select Query Results

    As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
    (this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)

    You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).

Posting Permissions

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



Click Here to Expand Forum to Full Width