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

  • Thread starter Thread starter desmcc
  • Start date Start date
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);
 
See other post.

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

***************************
Think Outside the Box!
***************************
 
Back
Top