简体   繁体   中英

visual basic 2010 - multiple queries to a table

I am setting up an order menu that has draft beer, bottled beer, and food.

I drag and drop the items to the menu and connect them to the database I have connected to the project. I have told VB, using the Query builder, to run a different query depending on what the drop box is. Each drop box is a separate category (Bottled, Draft, and Food) but pull from the same table. I do get it to display items in the 3 drop downs, but they're all reverting to category ID 1 (Bottled Beer) when I keep telling the Query builder to get Category_ID 2, or 3 for Draft, and Food respectively.

Am I doing something wrong? I just want 3 separate queries, one for each drop down, for the same table. Can I run the queries in the VB source instead of using the GUI menus, since it obviously isn't cooperating? The database is a MS Access 2010 Database.

Any guidance would be appreciated,

Thank you!

You could try something like this

    sub UsingSQLFromCode()
         Dim dbSource As String = "Data Source = Path to your database"
         Dim dbProvider As String = "Provider=Microsoft.ACE.OLEDB.12.0;"
         Dim con As New OleDb.OleDbConnection(dbProvider & dbSource)
         Dim cmd As New OleDb.OleDbCommand
         Try
                    sql = "Whatever your sql is"
                    cmd.CommandText = sql
                    cmd.Connection = con
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                Catch ex As OleDbException
                    con.Close()
                    MsgBox("An Error Occured")
                    Exit Sub
                End Try


            End Sub

Reference http://www.connectionstrings.com/access-2007

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM