locked
Calling sybase stored procedure with parameters RRS feed

  • Question

  • User1817555867 posted

    I'm having a problem calling a stored procedure in a sybase database. It keeps telling me that the parameters are not being supplied even though I am including them in my code. Here is my code:

    public DataSet executeSP(string sp, string nace, string timePeriod)
        {

            OdbcConnection myconn = new OdbcConnection(sConnStringDB);
            myconn.Open();
            OdbcCommand cmd = new OdbcCommand();
            OdbcDataAdapter da = new OdbcDataAdapter();
            DataSet ds = new DataSet();
            cmd = new OdbcCommand(sp, myconn);

            cmd.CommandType = CommandType.StoredProcedure;

            OdbcParameter myParm1 = cmd.Parameters.Add("@NACECode", OdbcType.VarChar, 20);
            myParm1.Value = nace;

            OdbcParameter myParm2 = cmd.Parameters.Add("@Timeperiod", OdbcType.VarChar, 20);
            myParm2.Value = timePeriod;

            da.SelectCommand = cmd;
            da.Fill(ds);
            myconn.Close();
            return ds;

        }

    This is the error I'm getting

    ERROR [HY000] [DataDirect][ODBC Sybase Wire Protocol driver][SQL Server]Procedure DBA_Indicators_S expects parameter @NACECode, which was not supplied.

    ERROR [HY000] [DataDirect][ODBC Sybase Wire Protocol driver][SQL Server]Procedure DBA_Indicators_S expects parameter @Timeperiod, which was not supplied.

    I'm confident the SP is correct as I can call it from elsewhere passing in parameters and it brings back expected results.

    Any help appreciated.

    Tuesday, September 27, 2011 4:57 AM

Answers

  • User1817555867 posted

    I solved it.

    I replaced

    cmd = new OdbcCommand(sp, myconn);

    with

    OdbcCommand Cmd = new OdbcCommand("{call DBA_Indicators_S(?,?)}", myconn);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 27, 2011 7:13 AM