Odbc fails with parameters

  • Thread starter Thread starter schick
  • Start date Start date
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
 
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();
 
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;";
 
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
 
Back
Top