Solved

Query combo box from another combo box result in vb express

Posted on 2014-07-23
2
253 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

729 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