Click here to Skip to main content
13,045,019 members (42,202 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i am trying to do a c# mysql
select * from table where variable =(selected tableColumn from dropdownlist)
like variable(text from text box does anyone know what the query should look like in my sql
Posted 10-Oct-12 23:00pm
Updated 10-Oct-12 23:54pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

MySqlCommand cmd = new MySqlCommand("Select * from table where variable = '@selectedValue'");
cmd.Parameters.AddWithValue("@selectedValue", value);
mrDivan 11-Oct-12 10:59am
Hi Marcus

Thank you for your response
here is my code im trying to use the selected value from a dropdown list as a variable but that seems broken

protected void btnFilter_Click(object sender, EventArgs e)

string filterlist = ddFillist.SelectedItem.Value;
string filterText = " % " + txtFilter.Text + "%";
MySql.Data.MySqlClient.MySqlConnection myconfill = new MySqlConnection(GetConnectionString());
if (myconfill.State != ConnectionState.Open)
catch (MySqlException ex)
throw (ex);

// where ?filterList like ?filterText
MySqlCommand sqlC = new MySqlCommand("select * from T_company where ?filterlist like ?filterText ", myconfill);
MySqlDataAdapter da = new MySqlDataAdapter(sqlC);

sqlC.Parameters.AddWithValue("?filterlist", filterlist);

DataSet ds = new DataSet();
gdvauthors.DataSource = ds;
if i change ? filterlist with company_name it works seems like im somehow not giving my parameter the right vale
Marcus Kramer 11-Oct-12 11:02am
Why the ?filterlist. The accepted way to use parameters is @filterlist.
Maciej Los 11-Oct-12 13:33pm
Good answer, my 5!
mrDivan 12-Oct-12 2:43am
Ho I changed the parameters back to@filterlist but it doesnt work but thanks for your help anyway
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

turns out you cannot use column names as a parameter in mysql so I wrote I different select statement for each column chose from the dropdown list
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

select * from table where variable in (selected tableColumn from dropdownlist)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100