Problems with parameter using ODBC prov. for ADO.NET

  • Thread starter Thread starter David Conorozzo
  • Start date Start date
D

David Conorozzo

I basically have an insert query that I am trying through
the ODBC provider for ADO.NET. I use a DSN to connect and
it works. Queries also work if I don't use parameters.
I create the command and set the text to something like
(it depends a little on the database):
INSET INTO table1 (col1, col2) VALUES (@param0, @param1)

I set the parameters like:
ocomm.parameters.add("@param0", value)

This works fine with other providers (SQL, OLEDB). I get
a slightly different error when my DSN is pointing to a
SQL Server DB as opposed to an Access DB (which I would
expect). I have tried really simple inserts also, just a
single parameter of type varchar. I have also tried
explicitly setting all of the info on the parameter (type,
name, direction, size, precisions, etc...). Here are
examples of the SQL Server and Access problems (I have
been looking for hours and hours for a solution but all I
find are people who have used " to surround character data
or didn't use quotes or something obvious):

Using a DSN that goes to SQL Server:
The parameter values are set to a byte array and a string
(respectively).
Here is my command text:
INSERT INTO "dbo"."table1"
("TestFile","TestFile_OriginalFileName") VALUES
(@param0,@param1)

Here is the table layout:
TestFile image
TestFile_OriginalFileName nvarchar 69

Here is the error:
ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL
Server]Must declare the variable '@param0'.


Using a DSN that goes to MS Access:
The parameter values are set to a byte array and a string
(respectively).
Here is my command text:
INSERT INTO `table1`
(`TestFile`,`TestFile_OriginalFileName`) VALUES
(@param0,@param1)

Here is the table layout:
TestFile OLE Object
TestFile_OriginalFileName TEXT 69

Here is the error:
ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]
Invalid precision value

NOTE: The quote characters used to qualify the table names
and column names are determined using API calls and should
be fine. I have tried removing them and even using ones
that have worked in the past, but it did not make a
difference.
 
Sorry, one more thing. In Access, if I try setting the
ODBC types on the parameters I get:
ERROR [07002] [Microsoft][ODBC Microsoft Access Driver]
Too few parameters. Expected 2.
 
Back
Top