Solved

Query combo box from another combo box result in vb express

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

829 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