OdbcParameter problem

M

Mike McCarthy

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_DSN;UID=FireRMS5_USER;PWD=98953");

myConnection.Open();



OdbcCommand myCommand = new OdbcCommand("get_nextid", myConnection);

myCommand.CommandType = CommandType.StoredProcedure;

OdbcParameter workParam = null;

workParam = myCommand.Parameters.Add("@next_id", OdbcType.Int);

workParam.Direction = ParameterDirection.Output;

myCommand.ExecuteNonQuery();

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

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

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

return myid;

}
 
J

Jonathan Schafer

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
 
J

Jonathan Schafer

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


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 said:
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


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_DSN;UID=FireRMS5_USER;PWD=98953");

myConnection.Open();



OdbcCommand myCommand = new OdbcCommand("get_nextid", myConnection);

myCommand.CommandType = CommandType.StoredProcedure;

OdbcParameter workParam = null;

workParam = myCommand.Parameters.Add("@next_id", OdbcType.Int);

workParam.Direction = ParameterDirection.Output;

myCommand.ExecuteNonQuery();

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

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

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

return myid;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top