Solved

MYSQL Select Command with variable as field name

Posted on 2011-09-13
5
555 Views
Last Modified: 2012-05-12
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
Comment
Question by:whiwex
[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
5 Comments
 
LVL 8

Expert Comment

by:pdd1lan
ID: 36531374
have you tried like below

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

Author Comment

by:whiwex
ID: 36531580
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
 
LVL 22

Accepted Solution

by:
pivar earned 500 total points
ID: 36531892
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36532076
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
 

Author Closing Comment

by:whiwex
ID: 36532405
thanks that was it
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

697 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