Click here to Skip to main content
11,480,701 members (62,658 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# MySQL
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 11-Oct-12 0:00am
Edited 11-Oct-12 0:54am
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 at 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 at 11-Oct-12 11:02am
Why the ?filterlist. The accepted way to use parameters is @filterlist.
Maciej Los at 11-Oct-12 13:33pm
Good answer, my 5!
mrDivan at 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
0 Sergey Alexandrovich Kryukov 294
1 Richard MacCutchan 150
2 OriginalGriff 145
3 CHill60 130
4 CPallini 125
0 Sergey Alexandrovich Kryukov 8,184
1 OriginalGriff 7,556
2 Sascha Lefèvre 3,114
3 Maciej Los 2,491
4 Richard Deeming 2,335

Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2015
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