C# mysql parameterized query -


i have peace of code need retrieve data mysql. if use parameterized query not take actual parameter value instead takes parameter name value.

error: @choise must defined

mysqlconnection connection = new mysqlconnection(""); mysqldataadapter mysqldataadapter; dataset ds; private string columnvalue = xxx; private string choise = yyy; mysqlcommand command = connection.createcommand(); command.commandtext = "select * table2 " + columnvalue + " = @choise"; command.parameters.add(new mysqlparameter("@choise", choise)); ds = new dataset(); connection.open(); mysqldataadapter = new mysqldataadapter(command.commandtext, connection); mysqldataadapter.fill(ds); connection.close(); 

when run query like:

select * table2 xxx = @choise

instead of

select * table2 xxx = yyy. problem?

i have tried: command.parameters.add(new mysqlparameter("@choise", choise)); command.parameters.addwithvalue("@choise", choise);

it works fine when i'm using actual variables instead of parameters.

i think need run prepare() on command before adding parameters:

command.commandtext = "select * table2 " + columnvalue + " = @choise"; command.prepare(); command.parameters.addwithvalue("@choise", choise); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -