Q: How to fix stored procedure expects return parameter which was not supplied in C#? I have a stored procedure named 'sp_AddDevice' which accepts the following variables:
@DeviceID AS NVARCHAR(8),
@Device_location AS NVARCHAR(40),
@Device_asset AS NVARCHAR(7),
@Device_name AS NVARCHAR(50),
@Device_manuf AS NVARCHAR(25),
@Device_model AS NVARCHAR(20),
@Device_serial AS NVARCHAR(40),
@Device_other AS NVARCHAR(20),
@Device_status AS SMALLINT,
@Device_type AS SMALLINT,
@EnteredBy AS VARCHAR(50),
@ChangedBy AS VARCHAR(50),
@errStatusOK INT OUTPUT

What bothers me is the Variable '@errStatusOK INT OUTPUT'
I am calling the stored procedure like this but I receive the error that the variable '@errStatusOK' is not supplied:
SqlCommand command = new SqlCommand(@"BCS_Verify.dbo.sp_AddDevice", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@DeviceID", SqlDbType.NVarChar, 8).Value = deviceID;
command.Parameters.Add("@Device_location", SqlDbType.NVarChar, 40).Value = location;
command.Parameters.Add("@Device_asset", SqlDbType.NVarChar, 7).Value = deviceID.ToLower().TrimStart('b','c','s');
command.Parameters.Add("@Device_name", SqlDbType.NVarChar, 50).Value = type;
command.Parameters.Add("@Device_manuf", SqlDbType.NVarChar, 25).Value = brand;
command.Parameters.Add("@Device_model", SqlDbType.NVarChar, 20).Value = model;
command.Parameters.Add("@Device_serial", SqlDbType.NVarChar, 40).Value = serial;
command.Parameters.Add("@Device_other", SqlDbType.NVarChar, 20).Value = "N/A";
command.Parameters.Add("@Device_status", SqlDbType.SmallInt).Value = status;
command.Parameters.Add("@Device_type", SqlDbType.SmallInt).Value = 0;
command.Parameters.Add("@EnteredBy", SqlDbType.NVarChar, 50).Value = GlobalVar.Default.Username;
command.Parameters.Add("@ChangedBy", SqlDbType.NVarChar, 50).Value = GlobalVar.Default.Username;
var returnParameter = command.Parameters.Add("@errStatusOK", SqlDbType.Int);
returnParameter.Direction = ParameterDirection.ReturnValue;
command.ExecuteNonQuery();
if (returnParameter.SqlValue.ToString() == "1") return true;
else return false;


do I have to define the return variable differently or what might be the issue?

A: Try this, maybe it's enough to change parameter direction from result to output:
SqlParameter errStatusOK = new SqlParameter
            {
                ParameterName = "@errStatusOK",
                IsNullable = false,
                Direction = ParameterDirection.Output,
                SqlDbType = SqlDbType.Int,
                Value = 0,
            };
     command.Parameters.Add(errStatusOK);
     command.ExecuteNonQuery(); 
     int returnValue = (int)commad.Parameters["@errStatusOK"].Value;


A: I use something like this:
command.Parameters.Add("@errStatusOK", SqlDbType.Int).Direction =
ParameterDirection.Output;

Then after execution of the query...
command.ExecuteNonQuery(); 
int iRetVal = Convert.ToInt32(commad.Parameters["@errStatusOK"].Value);

