.net - SQL Stored Call not passing parameter -


i have sql server 2008 stored procedure when called via code shown below returns missing parameter exception @batchid parameter.

as can see passing in parameter with

cmd.parameters.addwithvalue("@batchid", batchid) 

but reason not picking when making call server.

probably missing simple here, been long day.

stored procedure

alter procedure [dbo].[spisenginesixcylinderbybatchid]     @batchid int begin     set nocount on;      declare @issixcylinder bit     set @issixcylinder = 0      select @issixcylinder = tblbatches.sixcylinder         tblbatches         idbatch = @batchid      select @issixcylinder end 

code

private function isbatchsixcylinder(batchid int32) boolean     dim issixcylinder boolean = false      try         using cmd new sqlclient.sqlcommand("[dbo].[spisenginesixcylinderbybatchid]", _conn)             cmd.parameters.addwithvalue("@batchid", batchid)             issixcylinder = cmd.executescalar         end using      catch ex sqlclient.sqlexception         logerror(ex.message)     end try      return issixcylinder  end function 

exception

procedure or function 'spisenginesixcylinderbybatchid' expects parameter '@batchid', not supplied.

call stack

   @ system.data.sqlclient.sqlconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction)    @ system.data.sqlclient.sqlinternalconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction)    @ system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj, boolean callerhasconnectionlock, boolean asyncclose)    @ system.data.sqlclient.tdsparser.tryrun(runbehavior runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj, boolean& dataready)    @ system.data.sqlclient.sqldatareader.tryconsumemetadata()    @ system.data.sqlclient.sqldatareader.get_metadata()    @ system.data.sqlclient.sqlcommand.finishexecutereader(sqldatareader ds, runbehavior runbehavior, string resetoptionsstring)    @ system.data.sqlclient.sqlcommand.runexecutereadertds(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, boolean async, int32 timeout, task& task, boolean asyncwrite)    @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method, taskcompletionsource`1 completion, int32 timeout, task& task, boolean asyncwrite)    @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method)    @ system.data.sqlclient.sqlcommand.executescalar()    @ classlib_saptoepms.clssaptoepms.isbatchsixcylinder(int32 batchid) in c:\users\phil.murray\desktop\epms_05022012\epms_05022012\power systems epms\classlib_saptoepms\classlib_saptoepms\clssaptoepms.vb:line 229 

can try whether code in below snippet working?

using cmd new sqlclient.sqlcommand("spisenginesixcylinderbybatchid", _conn)             cmd.commandtype = commandtype.storedprocedure             cmd.parameters.addwithvalue("@batchid", batchid)             issixcylinder = cmd.executescalar end using 

or

using cmd new sqlclient.sqlcommand("spisenginesixcylinderbybatchid", _conn)             cmd.commandtype = commandtype.storedprocedure             cmd.parameters.add("@batchid ", sqldbtype.int)             cmd.parameters("@batchid ").value = batchid end using 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -