0
votes

I am passing the below parameters from c# form. But getting error. I can not find where the reason is. Please help me.

SqlParameter[] arrParam = new SqlParameter[3];
arrParam[0] = new SqlParameter("@mRegNo", SqlDbType.BigInt, 8);
arrParam[0].Value = Convert.ToInt64(m);

arrParam[1] = new SqlParameter("@amount", SqlDbType.Decimal);
arrParam[1].Value = money;

arrParam[2] = new SqlParameter("@intResult", SqlDbType.Int);
arrParam[2].Direction = ParameterDirection.Output;

int result = objDUT.ExecuteSqlSP(arrParam, "Sp_Add_Moeny");

Here is the function below:

public int ExecuteSqlSP(SqlParameter[] arrParam, string strSPName)
{
        OpenConnection();
        _mDataCom.CommandType = CommandType.StoredProcedure;
        _mDataCom.CommandText = strSPName;
        _mDataCom.CommandTimeout = 30;

        for (int i = 0; i < arrParam.Length; i++)
        {
            _mDataCom.Parameters.Add(arrParam[i]);
        }

        _mDataCom.ExecuteNonQuery();

        int intResult = Int32.Parse(_mDataCom.Parameters["@intResult"].Value.ToString());

        CloseConnection();
        DisposeConnection();

        return intResult;
}

Please suggest a solution. Thanks

1
Where do you definte, Sp_Add_Moeny how many params does it expect? - JeffUK
What error? What does googling it find? Please read & act on minimal reproducible example. - philipxy
Side note: you should not use the sp_ prefix for your stored procedures. Microsoft has reserved that prefix for its own use (see Naming Stored Procedures), and you do run the risk of a name clash sometime in the future. It's also bad for your stored procedure performance. It's best to just simply avoid sp_ and use something else as a prefix - or no prefix at all! - marc_s

1 Answers

0
votes

You are specifying arguments that stored procedure isn't expecting. Make sure that your stored proc has three arguments corresponding to

1.mRegNo
2.amount
3.intResult (you haven't posted a snippet of your proc, which you should so that we can see how you've declared this in SQL)

if the number of parameters are same then check if parameter data types match with their counterparts in stored proc

Hope this helps !