none
retrieving all sql column data into a listbox RRS feed

  • Question

  • Im trying to display all data in a sql database column which depends on input from the user so the column read would be different depending on the input. Any help would be appreciated heaps.

     

    Thanks

     

    Sunday, June 24, 2007 3:14 AM

All replies

  • Hi programpleb,
      I am moving this thread from Visual Basic Express Edition forum to the .NET Framework Data Access and Storage forum, since the issue is related to SQL data querying. There are more ADO.net experts in the .NET Framework Data Access and Storage forum.
    Thanks for your understanding!
    Tuesday, June 26, 2007 8:27 AM
  • Could yoy be a little more specific, casue I dont really understand hat is it you are looking for. Your problem sounds solvable but try and be more specific and explanatory.

    Tuesday, June 26, 2007 9:01 AM
  • Different in term of different number of rows from the same column in a table or from different column in a different table?

    In first case you could limit your selection placing WHERE clause into you SELECT statement that selects data from the database and pass user input as a parameter of the query. So your could would look like

     



    Dim MyCMD As SqlCommand = New SqlCommand & ("SELECT MyColumn FROM MyTable WHERE SomeColumn = @UserInputValue", MyConnectionHere)
    MyCMD.CommandType = CommandType.Text
    Dim MyParam As SqlParameter = testCMD.Parameters.Add & ("@UserInputValue", SqlDbType.VarChar, 100)
    MyParam .Value = UserInputValueHere


    Now you could use MyCMD command to get the data.

    In a second scenario, you basically need to execute different SQL statement, depending on user input

    Tuesday, June 26, 2007 10:41 AM
    Moderator
  • Ok Basically I am making a wine tasting database to help me with work (winemaker) and we do blind tastings on a regular basis and I would like to keep information and scores and didcriptions to pull out at a later time. Now I have set a an aroma database that depending on the type of wine it should display in a listbox aromas common to that variety. So the table is set up with a primary key and then the rest of the collumns contain arromas common to a variety

     

    so...table looks something like this

     

    primary key                              Pinot Noir                 Chardonnay               Sauvignon Blanc

             1                                          Plum                           apple                          Lychee

              2                                         Cherry                        Pineapple                  Gooseberry

    etc

     

    So when some selects Pinot Noir it should then pull onto the listbox  Plum

                                                                                                                        Cherry

                                                                                                                        Etc

     

    Hope this makes more sense

     

     

     

     


     

    Wednesday, June 27, 2007 3:31 AM
  • I believe you need to normalize your tables in a database first. Your current structure is incorrect and should contain two tables at least - one for the wine types and second for the tastes where primary key from one table should be reference in another one, like

     

    Wines Table

     

    primary key                                             

             1                                          Pinot Noir                           

             2                                         Chardonnay                                      

             3                                         Sauvignon Blanc

    Tastes Table

     

    primary key                              Taste                      ParentID

             1                                          Plum                           1                         

             2                                         Cherry                         1                 

             3                                         apple                           2

             4                                         Pineapple                   2

             5                                         Lychee                        3

               6                                         Gooseberry                3

     

    Now when someone select data for the wine type from Wines Table, you need to pull tastes from the Tastes table using next kind of query

     

    SELECT Taste FROM Tastes WHERE ParentID= Here you should specify selected primary key value from the Wines table

    Wednesday, June 27, 2007 10:23 AM
    Moderator