Output parameter issue in sql server and c# -
why if have stored procedure created output parameter, i'm getting following error:
sp_dts_insertlsrbatch expects parameter @errormsg not supplied
stored procedure code:
set ansi_nulls on set quoted_identifier on go alter procedure [dbo].[sp_dts_insertlsrbatch] @lsrnbr varchar(10), @batchnbr varchar(10), @errormsg varchar(20) output begin set nocount on; if not exists(select * tbldts_lsrbatch (nolock) lsrnbr=@lsrnbr , batchnbr=@batchnbr) begin -- check if batchnbr exists under lsr -- if not add (lsr, batchnbr) else error if not exists(select * tbldts_lsrbatch (nolock) batchnbr=@batchnbr) insert tbldts_lsrbatch (lsrnbr,batchnbr) values (@lsrnbr, @batchnbr) else set @errormsg = 'batch dif lsr' end end
c# code:
sqlconnection conn = new sqlconnection(connstr); try { conn.open(); (int = 0; <= lbxbatch.items.count - 1; i++) { sqlcommand cmd = new sqlcommand("sp_dts_insertlsrbatch", conn); cmd.parameters.add(new sqlparameter("@lsrnbr", txtlsr.text)); cmd.parameters.add(new sqlparameter("@batchnbr", lbxbatch.items[i].tostring())); //output parameter "errormsg" sqlparameter perrormsg = new sqlparameter("@errormsg", sqldbtype.varchar, 20); perrormsg.direction = parameterdirection.output; cmd.commandtype = commandtype.storedprocedure; cmd.executenonquery(); <--- error
in code haven't added perrormsg parameter. add line:
cmd.parameters.add(perrormsg);
Comments
Post a Comment