TROUBLE LOADING A COMBOBOX BASED ON SELECTED TEXT FROM ANOTHER COMBOBOX

Hey, I'm having trouble loading a 2nd combo box based on event textchanged from a 1st Combo Box
Here is vb part.
 Private Sub tsbcmbBuilding_Click(sender As Object, e As EventArgs) Handles tsbcmbBuilding.Click
        Using con As New OleDbConnection(connectionString)
            Using cmd As New OleDbCommand("SELECT * FROM NAZOU WHERE Building = '& tsbcmbBuilding.Text &'", con)
                con.Open()
                Using dt As New DataTable
                    dt.Load(cmd.ExecuteReader)
                    cmbOU.DataSource = dt
                    cmbOU.DisplayMember = "OU"
                    cmbOU.ValueMember = "ID"
                End Using
            End Using
            con.Close()
        End Using
    End Sub

Open in new window

Here is a visual of appvb app
Here is MS Access Data I'm trying to load into combo box
ms access table
powerztomAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
Your quotes look misplaced for starters.  Try this, and if that does not work, post back detailing exactly HOW it does not work (error message...Which one?   Incorrect results... what are the expected results vs the results you are getting?)

Using cmd As New OleDbCommand("SELECT * FROM NAZOU WHERE Building = '" & tsbcmbBuilding.Text & "'", con)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Éric MoreauSenior .Net ConsultantCommented:
In 2007, I have written an article showing how to create a relation between 2 combos. You can read it from http://emoreau.com/Entries/Articles/2007/01/Setting-a-masterdetail-relationship-between-two-ComboBox.aspx
0
powerztomAuthor Commented:
Eric I enjoyed your code and article I actually learned a few things but doesn't get me there
so can't get 2nd combo to load
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Éric MoreauSenior .Net ConsultantCommented:
have you tried my sample?
0
mbizupCommented:
Did you see my post at the top of the thread?

An issue with the syntax in your original post is that the way the quotes are placed the control name is being used literally, rather than the value held in the control.

Just curious whether you tried it and what the results were.
0
mbizupCommented:
It looks like you're trying to implement Scott McDaniel's solution here:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_28670628.html#a40770190

Again, the issue is that you've put  '& tsbcmbBuilding.Text &' inside the double quotes.  That makes your query look for the exact, literal text  '& tsbcmbBuilding.Text &', which it will find no matches for (so nothing will load in the dropdown list).

To have the query look for the value held in tsbcbmMuilding, you need to write line 3 in your original post like this, with the tsbcmbBuilding.Text outside of the double quotes, with the &'s concatenating it's value to the literal text:

Using cmd As New OleDbCommand("SELECT * FROM NAZOU WHERE Building = '" & tsbcmbBuilding.Text & "'", con)

Open in new window

0
Helen FeddemaCommented:
Try putting the value from tsbcmbBuilding into a String variable.  This will let you examine it in the Immediate Window to see if there are any problems with the SQL statement.
0
ArkCommented:
Just an advice - looking on your code and db data it seems u'r using NAZOU table much more often for select then for Update/Delete/Insert/ In this case IMHO more wise is to fill table in the beginning and refresh after Update/Delete/Insert with simple "SELECT * FROM NAZOU" query.
when you need to use filtered query as datasource, use either DataTable.Select method:
Dim source = dtOU.Select("Building='" & tsbcmbBuilding.Text & "'")

Open in new window

or LINQ
Dim source = (From x In dtOU.AsEnumerable() _
              Where x.Field(Of String)("Building") = tsbcmbBuilding.Text).ToList

Open in new window

0
powerztomAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.