• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 572
  • Last Modified:

MYSQL Select Command with variable as field name

What is the syntex to select records from a mysql database using a variable as the field name.
i.e. select * from database where myvariable = '" & "test" & "'   the myvariable will be a field name selected by the user from a drop down list.
0
whiwex
Asked:
whiwex
1 Solution
 
pdd1lanCommented:
have you tried like below

select * from database where myvariable ='" & Combobox1.Text & "'"
0
 
whiwexAuthor Commented:
yes it treats myvariable as a fieldname so it errors to unknown column name myvariable
I need it to treat the contents of the myvariable as the field name
0
 
pivarCommented:
Hi,

I suppose you're talking about creating sql statement in VB? Is it this you're looking for?

"select * from database where " & myvariable & " ='" & Combobox1.Text & "'"

/peter
0
 
CodeCruiserCommented:
Well I think it would be

MyCommand.Text = "select * from database where " & combobox1 & " ='" & txtSearch.Text & "'"


where MyCommand is the MySQL command object in VB.NET
0
 
whiwexAuthor Commented:
thanks that was it
0

Featured Post

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now