Odbc fails with parameters

S

schick

Posted this to 'ado' group earlier but getting no replies...

I have a C# app that uses the base "System.Data" interfaces so it can
switch between Oledb and Odbc (mostly accessing a Jet database).
Everything has worked until I tried using parameters. The code below
works perfectly in Oledb mode, but fails under Odbc. The Odbc error is
"ERROR [07002] [Microsoft][ODBC Microsoft Access Driver] Too few
parameters". Is there something I missed that the Odbc Access driver
needs but the Oledb driver doesn't?

// create cmd and open connection
byte[] data = GetData();

cmd.CommandText = "UPDATE ImageTable SET " +
"fFolderInfoArray=@FIA " +
"WHERE fImageId=10;";

IDbDataParameter param = cmd.CreateParameter();
param.DbType = System.Data.DbType.Binary;
param.Size = data.Length;
param.Value = data;
param.ParameterName = "@FIA";
cmd.Parameters.Add(param);

cmd.ExecuteNonQuery();


Thanks,
Brad
 
S

schick

I temporarily hard-coded this to use Odbc specific types (as show below)
and it still fails with the same error. Does anyone know if parameters even
work with the Odbc Acesss Driver in Ado.Net?

OdbcConnection newconn = new OdbcConnection( "Driver={Microsoft "+
"Access Driver (*.mdb)};DBQ=" + dbName );
newconn.Open();

OdbcCommand newcmd = new OdbcCommand(
"UPDATE ImageTable SET " +
"fFolderInfoArray = @FIA " +
"WHERE fImageId=10;";

byte[] data = GetData();
newcmd.Parameters.Add("@FIA", System.Data.Odbc.OdbcType.Binary,
data.Length).Value = data;
newcmd.ExecuteNonQuery();
 
?

=?ISO-8859-1?Q?Carlos_Guzm=E1n_=C1lvarez?=

Hello:
OdbcCommand newcmd = new OdbcCommand(
"UPDATE ImageTable SET " +
"fFolderInfoArray = @FIA " +
"WHERE fImageId=10;";

If i'm not wrong you need to use the placeholder ( named parameters
cannot be used with the ODBC provider if i'm not wrong )

OdbcCommand newcmd = new OdbcCommand(
"UPDATE ImageTable SET " +
"fFolderInfoArray = ? " +
"WHERE fImageId=10;";
 
S

schick

If i'm not wrong you need to use the placeholder ( named parameters
cannot be used with the ODBC provider if i'm not wrong )

Excellent, that solved the problem. Thanks for the help Carlos, greatly
appreciated!

-Brad
 

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