Solved

Query combo box from another combo box result in vb express

Posted on 2014-07-23
2
251 Views
Last Modified: 2014-07-25
Trying to query a combobox from another combobox result in vb express.  Getting an error near "=" on the select ProductCode query - makes no sense to me as i can't see any obvious error.  

 Private Sub GetMachine()
        'Query product code table
        If SQL.SQLDataSet IsNot Nothing Then
            SQL.SQLDataSet.Clear()
        End If
        cboMachine.Items.Clear() 'empty combo box
        SQL.RunQuery("SELECT Machine FROM tbl_MachineList")
        MsgBox(SQL.recordcount)
        If SQL.recordcount > 0 Then
            For Each r As DataRow In SQL.SQLDataSet.Tables(0).Rows
                cboMachine.Items.Add(r("Machine")) 'machine column
            Next
            '      cboMachine.SelectedIndex = 0 'set combo box on 1st record
        ElseIf SQL.Exception <> "" Then
            MsgBox(SQL.Exception)
        End If
    End Sub

    Private Sub GetProductCode(Machine As String)
        If SQL.SQLDataSet IsNot Nothing Then
            SQL.SQLDataSet.Clear()
        End If
        'Run query
        SQL.RunQuery("SELECT ProductCode FROM tbl_ProductStandards" & _
>>                               "WHERE Machine = '" & cboMachine.Text & "' ")                      << This line
        If SQL.recordcount > 0 Then
            For Each r As DataRow In SQL.SQLDataSet.Tables(0).Rows
                cboProductCode.Items.Add(r("ProductCode")) 'product code column
            Next
        ElseIf SQL.Exception <> "" Then
            MsgBox(SQL.Exception)
        End If
    End Sub

    Private Sub cboMachine_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboMachine.SelectedIndexChanged
        GetProductCode(cboMachine.Text)
    End Sub
0
Comment
Question by:SweetingA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:SweetingA
ID: 40215855
OK sorted it out somehow....

    Private Sub GetMachine()
        'Query product code table
        If SQL.SQLDataSet IsNot Nothing Then
            SQL.SQLDataSet.Clear()
        End If
        cboMachine.Items.Clear() 'empty combo box
        SQL.RunQuery("SELECT Machine FROM tbl_MachineList")
        MsgBox(SQL.recordcount)
        If SQL.recordcount > 0 Then
            For Each r As DataRow In SQL.SQLDataSet.Tables(0).Rows
                cboMachine.Items.Add(r("Machine")) 'machine column
            Next
            '      cboMachine.SelectedIndex = 0 'set combo box on 1st record
        ElseIf SQL.Exception <> "" Then
            MsgBox(SQL.Exception)
        End If
    End Sub

    Private Sub GetProductCode()
        If SQL.SQLDataSet IsNot Nothing Then
            SQL.SQLDataSet.Clear()
        End If
        cboProductCode.Items.Clear() 'empty combo box
        SQL.RunQuery("SELECT ProductCode FROM tbl_ProductStandards WHERE Machine ='" & cboMachine.Text & "' ")
        If SQL.recordcount > 0 Then
            For Each r As DataRow In SQL.SQLDataSet.Tables(0).Rows
                cboProductCode.Items.Add(r("ProductCode")) 'product code column
            Next
        ElseIf SQL.Exception <> "" Then
            MsgBox(SQL.Exception)
        End If
    End Sub

    Private Sub cboMachine_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboMachine.SelectedIndexChanged
        GetProductCode()
    End Sub
0
 
LVL 15

Accepted Solution

by:
JimFive earned 500 total points
ID: 40217095
The issue was that you didn't have a space before the WHERE.  I always like to put my SQL statements into a string variable and then echo the variable to make sure that I'm getting the statement that I expect.  Missing spaces and quotes are usual culprits.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question