Solved

MYSQL Select Command with variable as field name

Posted on 2011-09-13
5
545 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
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now