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);

RE: Using parameters in a SQL OleDb provider leads to "must declare va by NoSpamMgbworld

NoSpamMgbworld
Fri Jun 24 09:13:02 CDT 2005

See other post.

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

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


"desmcc@gmail.com" wrote:

> 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);
>
>