sql server 2008 - Input - Output parameter in same call to stored procedure - C# -


using (var con = connection)             {                 con.open();                 using (var cmd = new sqlcommand("usp_students", con))                 {                     cmd.commandtype = commandtype.storedprocedure;                     sqlparameter sp = cmd.parameters.addwithvalue("@studentids", studentid);                     sp.sqldbtype = sqldbtype.structured;                     cmd.executenonquery();                 }             } 

i inputing value stored procedure in case want value too. how can incorporate output in above code?

create procedure usp_students       @studentid students readonly,       @numberofstudents int output, 

try way

using (var con = connection) {     con.open();     using (var cmd = new sqlcommand("usp_students", con))     {         cmd.commandtype = commandtype.storedprocedure;         sqlparameter sp = cmd.parameters.addwithvalue("@studentids", studentid);         sp.sqldbtype = sqldbtype.structured;          sqlparameter code = new sqlparameter("@numberofstudents", sqldbtype.int);         code.direction = parameterdirection.output;         cmd.parameters.add(code);          cmd.executenonquery();          // getting output value         int numberofstudent = convert.toint32(cmd.parameters["@numberofstudents"].value);      } } 

thanks

manoj


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -