Reputation: 11
I want to dynamically change the name of the column in my sqlstatement every time I select an item name similar of the columns on the cmbcategory comboBox. Then use it to get its data to be transferred to the cmbparts comboBox. Is it possible?
This is my sample code:
Public Sub cmbpartfill()
sqlstatement = "select '" & cmbcategory.Text & "' from tblparts"
Connect()
command = New MySqlCommand(sqlstatement, connection)
reader = command.ExecuteReader
While reader.Read
cmbpart.Items.Clear()
cmbpart.Items.Add(reader.Item(0).ToString)
End While
Disconnect()
End Sub
I would appreciate any help. Thanks.
Upvotes: 0
Views: 41
Reputation: 345
This will work I think...............
sqlstatement = "select " & cmbcategory.Text & " from tblparts"
Edited: Just try i am not sure............
sqlstatement = "select [" & cmbcategory.Text & "] from tblparts"
Upvotes: 1
Reputation: 593
Use a backticks "`" instead of Single Quotes "'".
sqlstatement = "select `" & cmbcategory.Text & "` from tblparts"
Upvotes: 0