Parameter expected?

A

andrewbb

It keeps saying the stored procedure expects the parameter '@entity'
which was not suppplied, but I'm supplying it:

OdbcConnection cn = new OdbcConnection(CNSTR);
OdbcCommand cmd = new OdbcCommand("GetMyList", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@entity", OdbcType.VarChar, 4);
cmd.Parameters.Add("@type", OdbcType.VarChar, 4);
cmd.Parameters["@entity"].Value = "PRAC";
cmd.Parameters["@type"].Value = "TYPE";
cn.Open();
OdbcDataReader reader = cmd.ExecuteReader();
cn.Close();

If I substitute a SQL statement (no parameters) all is good. What I am
I doing wrong on the parameter creation/adding?

Thanks in advance.
 
V

Val Mazur \(MVP\)

Hi,

Could be something related to the reserved words. If you have any reserved
words as a column names in your SQL statement you could get this type of
error. What is your SP?
 
A

andrewbb

I changed all the parameter column names to make sure it's not a
reserved word, but it still gives the same error. Here's the SP with
the modified names:

alter procedure dbo.GetMCTRList (
@aentity varchar(4),
@atype varchar(4)
) as

select
MCTR_VALUE as vVal,
MCTR_DESC as vDescr
from
mihsreport..CMC_MCTR_CD_TRANS
where
MCTR_ENTITY = @aentity
and MCTR_TYPE = @atype
 
A

andrewbb

Interesting that when I change the code to use SqlClient rather than
Odbc, everything works.

We're moving to Sybase soon, so using the SqlClient objects isn't a
long term solution.
 
V

Val Mazur \(MVP\)

Your code looks fine. Could be some sort of a bug. Actually moving to Sybase
could solve the problem, because you will use another ODBC driver. If it
does not solve, then you could be in a trouble even with OLEDB for Sybase. I
have pretty bad experience to work with Sybase with .NET. OLEDB provider for
Sybase has a number of bugs and in some cases you just do not have
workaround for them. .NET Managed provider for Sybase is extremely slow. I
have found that in some cases it works about 20 times slower than OLEDB
provider
 

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