Using parameters in a SQL OleDb provider leads to "must declare variable error"

D

desmcc

Hi I am using the code below to run a simple query using the SQlOledb
provider but for some reason, I get the error "must declare the
variable @BamDestination" when the SQL is executed. This works fine if
I use the SQL Server provider. Anyone any ideas ?


//Using oledb to support sybase as well as SQL server
OleDbConnection conn = null;

try
{
conn = new OleDbConnection(connectionString);
conn.Open();

string
sSQL = @"SELECT MESSAGEDATE, MESSAGEREF, RESPONSE FROM
GENERATEDRESPONSES WHERE DESTINATION = @BamDestination ORDER BY
GENERATEDDATE";

OleDbParameter [] arParms = new OleDbParameter[1];
string bamDestination = "BAM";
arParms[0] = new
OleDbParameter("@BamDestination",OleDbType.VarWChar);
arParms[0].Value = bamDestination;

OleDb oleDb = new OleDb();
return oleDb.ExecuteDataset(conn, CommandType.Text, sSQL,arParms);
 
G

Guest

See other post.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 

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