Query with User Entered Criteria

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rhonda2010
    New Member
    • Aug 2010
    • 4

    Query with User Entered Criteria

    My project consists of a user interface designed in Visual Studio 2010 Express. I have it linked to an Access database. At this time, I have two text boxes that the user will enter a number. I want to be able to write a query that will take the first and second number and pull the information from the database that is equal to or greater than the user entered number. I think the logic would be something like:

    Code:
         If numOne => {user entered number here} or
           If numTwo => {user entered 2nd number here} Then
        {open new form with columns of data}
    Now, I am assuming I have to dim numOne and numTwo. Do these need to be the column names of the data in Access? Also, when I design a new form, how do I tell it to put the data from the database?

    Thanks for any help you can provide.

    Also, my data is in one table with about 20 columns. I want to pull data from 10 of those columns based on if it meets the user specified criteria.
    Last edited by rhonda2010; Aug 17 '10, 03:51 PM. Reason: Additional information
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Hi Rhonda,

    To be able to get data from your Access database, you'll need to create a OleDB connection. I suggest you read the following articles that were provided by Bytes Experts:

    How to use a database in your program Part I

    How to use a database in your program Part II

    How to create a database connection without using wizards

    Good luck with that! If you have further questions, don't hesitate to come back!

    Steven

    Comment

    • rhonda2010
      New Member
      • Aug 2010
      • 4

      #3
      Steven,

      Thank you for your reply. I used the wizard to connect to my database.

      If you don't mind, let me lay out what I am trying to accomplish and you can tell me if it is possible with VB.Net (using Visual Studio 2010 Express).

      I have a database in MS Access with one table. I want to be able to query this database with multiple queries. At this time, I have a form set up with two text boxes. I want the user to be able to enter a number in each of these text boxes (as described above) and then select all of the information in the database (each row of information) where the percentages in either one of the two columns (or fields) (related to the text boxes) is => the user-entered number. I then want to display an additional form (like a report) with this information on it. I have the text boxes laid out on the additional form but need to know how to link those text boxes to the fields in the database.

      I will be adding some drop-down boxes to use in other queries. Then I would compare the percentages and the information in the drop-down box to display the data. I don't see why this would not be possible in VB. If it is; how do I code the text box to link to that specific column in the database?

      Thanks!
      Last edited by rhonda2010; Aug 19 '10, 01:17 PM. Reason: more info

      Comment

      • MrMancunian
        Recognized Expert Contributor
        • Jul 2008
        • 569

        #4
        I have the text boxes laid out on the additional form but need to know how to link those text boxes to the fields in the database.
        You need to create an event that checks both textbox values. Most common is a button that fires an event, but you could also use the TextChanged event of the textbox. However, as you are going to query your database, I'd choose for the button or something that is fired when the user clicks it.

        When you've checked the values of the textboxes, you store them in two separate variables. As you want them to be percentages, I'd choose for either Integer (rounded numbers), or Double (broken numbers). After that, you write a query, using the variables. It should something like this:
        Code:
        SELECT * FROM [table] WHERE [column] BETWEEN [variable1] AND [variable2]
        Now, try to figure out how to get the results of the query in a datatable and bind that table to your DropDownList.

        I don't see why this would not be possible in VB.
        Neither do I, everything is possible! :-)

        Good luck! If you need help, don't hesitate to come back.

        Steven

        Comment

        Working...