c# - Keep getting an error: Procedure or function 'usp_StoredProcName' expects parameter '@inputVal', which was not supplied -


i have simple stored procedure expects 1 input parameter , has 2 output parameters:

create procedure [dbo].[usp_storedprocname]     @inputval nvarchar(255),     @iserror bit output,     @errorinfo nvarchar(255) output begin declare @totalrow int = 0; declare @inputvalid uniqueidentifier;  set @iserror = 1; set @errorinfo = '';  select @inputvalid = [inputvalid] testtable inputval = @inputval;  if @inputvalid null begin     set @iserror = 0;     set @errorinfo = 'inputval not found';     return end end 

to execute parametrized stored procedure, have used couple of c# methods , return error:

procedure or function 'sp_storedprocname' expects parameter '@inputval', not supplied.

method 1 (to call parametrized stored procedure):

using (sqlconnection con = new sqlconnection(myfullconncectionstringtodb)) {    using (sqlcommand cmd = new sqlcommand("sp_storedprocname", con))    {       cmd.commandtype = commandtype.storedprocedure;        cmd.parameters.addwithvalue("@inputval", "myparamval_12345");        cmd.parameters["@iserror"].direction = parameterdirection.output;       cmd.parameters["@errorinfo"].direction = parameterdirection.output;        con.open();       cmd.executenonquery();        var iserror = cmd.parameters["@iserror"].value;       var errinfo = cmd.parameters["@errorinfo"].value;       con.close();    } } 

method 2 (to call parametrized stored procedure):

sqlconnection con = new sqlconnection(myfullconncectionstringtodb); sqlcommand cmd = new sqlcommand("sp_storedprocname", con); cmd.commandtype = commandtype.storedprocedure;  sqlparameter in_parm = new sqlparameter("@inputval", sqldbtype.nvarchar); in_parm.size = 255; in_parm.value = "myparamval_12345"; in_parm.direction = parameterdirection.input; cmd.parameters.add(in_parm);  sqlparameter out_parm = new sqlparameter("@errorinfo", sqldbtype.nvarchar); out_parm.size = 255; out_parm.direction = parameterdirection.output;  cmd.parameters.add(out_parm);  sqlparameter out_parm1 = new sqlparameter("@iserror", sqldbtype.bit); out_parm1.direction = parameterdirection.output;  cmd.parameters.add(out_parm1);  con.open(); cmd.executenonquery(); con.close(); 

both of above c# methods return same error:

procedure or function 'sp_storedprocname' expects parameter '@inputval', not supplied.

please tell me doing wrong here in c# code execute stored procedure.

i passing parameter value in both of methods can't figure out why keeps displaying error.

thank much!

you setting @inputval input parameter in line right after create procedure

create procedure [dbo].[sp_storedprocname]  @inputval nvarchar(255), 

and creating again further down uniqueidentifier.

declare @inputval uniqueidentifier; 

that's not valid syntax. change 1 or other. if don't want take input parameter (which eliminate error you're asking about), delete first.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -