asp.net - Calling a stored procedure with varchar as output parameter -
this question has answer here:
i want assign output parameter of stored procedure session variable.so,basically,i looking call stored procedure has varchar out parameter.the stored procedure follows:
alter proc spchecktaskperformed @taskid int, @email varchar(100), @status varchar(100) output begin select @status = status tbltaskperformed [email] = @email , [taskid]=@taskid end
the code have below:
private void checktaskperformed() { string cs = configurationmanager.connectionstrings["easyrozmoney_connectionstring"].connectionstring; using (sqlconnection con = new sqlconnection(cs)) { con.open(); sqlcommand cmd = new sqlcommand("spchecktaskperformed", con); cmd.commandtype = commandtype.storedprocedure; cmd.parameters.addwithvalue("@taskid", lbltaskid.text); cmd.parameters.addwithvalue("@email", session["email"].tostring()); sqlparameter outputparameter = new sqlparameter(); outputparameter.parametername = "@status"; outputparameter.sqldbtype = system.data.sqldbtype.varchar; outputparameter.direction = system.data.parameterdirection.output; cmd.parameters.add(outputparameter); cmd.executenonquery(); string status = outputparameter.value.tostring(); lblstatus.text = "this task has " + status; } }
but error message - string[2]: size property has invalid size of 0. @ below line.
cmd.executenonquery();
you must send value status or specify null input:
@status varchar(100) = null output
Comments
Post a Comment