OdbcParameter problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike McCarthy

    #1

    OdbcParameter problem

    When I execute the following code I get the error..

    Stored procedure get_nextid expects parameter @next_id which was not
    supplied

    What am I doing wrong

    public String GetNewKey()

    {

    String myid = "";

    OdbcConnection myConnection = new
    OdbcConnection( "DSN=RMS5SQL_DS N;UID=FireRMS5_ USER;PWD=98953" );

    myConnection.Op en();



    OdbcCommand myCommand = new OdbcCommand("ge t_nextid", myConnection);

    myCommand.Comma ndType = CommandType.Sto redProcedure;

    OdbcParameter workParam = null;

    workParam = myCommand.Param eters.Add("@nex t_id", OdbcType.Int);

    workParam.Direc tion = ParameterDirect ion.Output;

    myCommand.Execu teNonQuery();

    myid = myCommand.Param eters["@next_id"].Value.ToString ();

    //pad with "_000" to 14 length (Typical key in FireRMS)

    myid = myid.PadLeft(14 ,'0');

    return myid;

    }


  • Jonathan Schafer

    #2
    Re: OdbcParameter problem

    In the Stored Procedure, is @next_id declared as OUTPUT? Clearly it
    is in your code but it must also be set in the actual SP.

    Jonathan Schafer


    On Mon, 14 Jul 2003 14:24:55 -0400, "Mike McCarthy"
    <mmccarthy@aeth ersystems.com> wrote:
    [color=blue]
    >When I execute the following code I get the error..
    >
    >Stored procedure get_nextid expects parameter @next_id which was not
    >supplied
    >
    >What am I doing wrong
    >
    >public String GetNewKey()
    >
    >{
    >
    >String myid = "";
    >
    >OdbcConnecti on myConnection = new
    >OdbcConnection ("DSN=RMS5SQL_D SN;UID=FireRMS5 _USER;PWD=98953 ");
    >
    >myConnection.O pen();
    >
    >
    >
    >OdbcCommand myCommand = new OdbcCommand("ge t_nextid", myConnection);
    >
    >myCommand.Comm andType = CommandType.Sto redProcedure;
    >
    >OdbcParamete r workParam = null;
    >
    >workParam = myCommand.Param eters.Add("@nex t_id", OdbcType.Int);
    >
    >workParam.Dire ction = ParameterDirect ion.Output;
    >
    >myCommand.Exec uteNonQuery();
    >
    >myid = myCommand.Param eters["@next_id"].Value.ToString ();
    >
    >//pad with "_000" to 14 length (Typical key in FireRMS)
    >
    >myid = myid.PadLeft(14 ,'0');
    >
    >return myid;
    >
    >}
    >[/color]

    Comment

    • Jonathan Schafer

      #3
      Re: OdbcParameter problem

      I created the SP on our SqlServer 2k, and copied your code below to
      call it. However, I don't have .NET framework 1.1, so I had to change
      the Odbc stuff to Sql stuff (SqlConnection, SqlCommand).

      The code compile, ran, and returned the correct value. Without having
      the 1.1 framework, I can't reproduce the problem.

      Jonathan Schafer


      On Mon, 14 Jul 2003 16:19:06 -0400, "Mike McCarthy"
      <mmccarthy@aeth ersystems.com> wrote:
      [color=blue]
      >Here's a copy of the sotred procedure...
      >
      >CREATE PROCEDURE dbo.get_nextid @next_id int out AS
      >UPDATE nextid SET @next_id = id = id+1
      >
      >GO
      >
      >"Jonathan Schafer" <jschafer@*NOSP AM*brierley.a.b .c.com> wrote in message
      >news:l1v5hv4nt 897467n6n1pm5an 0f9hgod3dn@4ax. com...[color=green]
      >> In the Stored Procedure, is @next_id declared as OUTPUT? Clearly it
      >> is in your code but it must also be set in the actual SP.
      >>
      >> Jonathan Schafer
      >>
      >>
      >> On Mon, 14 Jul 2003 14:24:55 -0400, "Mike McCarthy"
      >> <mmccarthy@aeth ersystems.com> wrote:
      >>[color=darkred]
      >> >When I execute the following code I get the error..
      >> >
      >> >Stored procedure get_nextid expects parameter @next_id which was not
      >> >supplied
      >> >
      >> >What am I doing wrong
      >> >
      >> >public String GetNewKey()
      >> >
      >> >{
      >> >
      >> >String myid = "";
      >> >
      >> >OdbcConnecti on myConnection = new
      >> >OdbcConnection ("DSN=RMS5SQL_D SN;UID=FireRMS5 _USER;PWD=98953 ");
      >> >
      >> >myConnection.O pen();
      >> >
      >> >
      >> >
      >> >OdbcCommand myCommand = new OdbcCommand("ge t_nextid", myConnection);
      >> >
      >> >myCommand.Comm andType = CommandType.Sto redProcedure;
      >> >
      >> >OdbcParamete r workParam = null;
      >> >
      >> >workParam = myCommand.Param eters.Add("@nex t_id", OdbcType.Int);
      >> >
      >> >workParam.Dire ction = ParameterDirect ion.Output;
      >> >
      >> >myCommand.Exec uteNonQuery();
      >> >
      >> >myid = myCommand.Param eters["@next_id"].Value.ToString ();
      >> >
      >> >//pad with "_000" to 14 length (Typical key in FireRMS)
      >> >
      >> >myid = myid.PadLeft(14 ,'0');
      >> >
      >> >return myid;
      >> >
      >> >}
      >> >[/color]
      >>[/color]
      >[/color]

      Comment

      Working...