c# - How to use prepared statement using entity framework with MYSQL DB? -


i have been trying incorporate prepared statements application using ef 5.0. kindly @ script below.

int parametervalue = 100000; var addparameters = new list<mysqlparameter>(); var param1 = new mysqlparameter(); param1.direction = system.data.parameterdirection.input; param1.value = parametervalue; param1.parametername = "user_id"; addparameters.add(param1); db.database.executesqlcommand(@"delete tbl_user user_id = @user_id", addparameters); 

it produces error

exception: {"fatal error encountered during command execution."} innerexception: {"parameter '@user_id' must defined."} 

so based on innerexception description changed parameter nae "@user_id"

int parametervalue = 100000; var addparameters = new list<mysqlparameter>(); var param1 = new mysqlparameter(); param1.direction = system.data.parameterdirection.input; param1.value = parametervalue; param1.parametername = "@user_id"; addparameters.add(param1); db.database.executesqlcommand(@"delete tbl_user user_id = @user_id", addparameters); 

but still same error.

what doing wrong?

thanks in advance.

============================================== additional info

<package id="entityframework" version="5.0.0" targetframework="net40" /> <package id="mysql.data" version="6.7.4" targetframework="net40" /> <package id="mysql.data.entities" version="6.7.4.1" targetframework="net40" /> 

let me show practice code show want + recommendation on resource releasing:

using (sqlcommand comm = conn.createcommand()) //release practice {     comm.commandtext = "delete tbl_user user_id = @user_id";     comm.commandtype = commandtype.text; //can skipped case     comm.parameters.add(new sqlparameter("@user_id", sqldbtype.int)).value =         parametervalue;     comm.executenonquery(); } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -