.net - c# stored procedure launch: Procedure or function expects parameter, which was not supplied -
i've got stored procedure:
alter procedure [dbo].[sp_xnet_backup] @backuppath nvarchar(4000) = null, @rc int out begin set @rc = 0 ... ...
launched c# project in way:
sqlparameter[] paramters = new sqlparameter[2]; byte = 0; string sp = "dbo.sp_xnet_backup"; using (sqlconnection conn = dbmanager.createadoconnmaster()) { conn.open(); sqlcommand cmd = new sqlcommand(sp, conn); cmd.commandtype = commandtype.storedprocedure; paramters[i++] = new sqlparameter("@backuppath", completepath); paramters[i] = new sqlparameter("@rc", sqldbtype.int); paramters[i].direction = parameterdirection.inputoutput; foreach (sqlparameter param in paramters) cmd.parameters.add(param); cmd.executenonquery(); ... ...
but gives me error:
procedure or function 'sp_xnet_backup' expects parameter '@rc', not supplied.
rather using parameterdirection.inputoutput
, use parameterdirection.output
cmd.parameters.add("@rc", sqldbtype.int).direction = parameterdirection.output; try { if (cmd.connection.state == connectionstate.closed) { cmd.connection.open(); } cmd.executenonquery(); result = convert.toint32(cmd.parameters["@rc"].value); } catch (exception) { } { cmd.connection.close(); response.write(result); }
Comments
Post a Comment