?
Solved

MYSQL Select Command with variable as field name

Posted on 2011-09-13
5
Medium Priority
?
565 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

762 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