Clorae Clorae - 3 months ago 8
Vb.net Question

How to use the ComboBox.Text as the Column in the WHERE statement of the query?

How do i use the ComboBox.Text as the Column in the WHERE statement of the query?

Here's my code.

If cboShowOnly.Text = "Province" Then
valCbo = "Prov_Name"
ElseIf cboShowOnly.Text = "Municipality" Then
valCbo = "Mun_Name"
ElseIf cboShowOnly.Text = "Bank" Then
valCbo = "BANK_ACCNT"
ElseIf cboShowOnly.Text = "Branch" Then
valCbo = "Branch_Name"
ElseIf cboShowOnly.Text = "Assigned Account" Then
valCbo = "Assigned_Account"
End If

Select * from view_remit WHERE '" & valCbo & "' = '" & txtGroupBy.Text & "'"


the
Items
listed in the
cboShowOnly.text
are the
column
names of the
view_remit


here's the
Image of my code

here's what i want to happen >
Image of working mysql statement

am i doing it wrong? is there any other way?

Answer

valCbo is a field thus shall not be enclosed with a single quote(').

"Select * from view_remit WHERE " & valCbo  & " = '" & txtGroupBy.Text & "'"