G
Guest
I'm trying to use the .NET ODBC Adapter within a C# program.
A simple program does an insert into table "u" having one nvarchar column
"name", the actual value is passed as a parameter.
So the code is quite simple:
....
OdbcConnection conn = new OdbcConnection("DSN=xxx");
OdbcCommand command;
string s;
....
OdbcParameter p = new OdbcParameter("name",OdbcType.NVarChar,10,"name");
p.OdbcType = OdbcType.NVarChar;
string sql = "insert into u (name) values (?)";
s = "A";
p.Value=s ;
conn.Open ();
command = new OdbcCommand (sql,conn);
command.Parameters.Add (p);
command.ExecuteNonQuery ();
....
The problem here is, that the .NET ODBC defines the SQL datatype as
SQL_VARCHAR when calling SQLBindParameter(), while I would expect
SQL_WVARCHAR.
This can be seen in the ODBC trace:
260-e90 ENTER SQLBindParameter
HSTMT 00F31A10
UWORD 1
SWORD 1 <SQL_PARAM_INPUT>
SWORD -8 <SQL_C_WCHAR>
SWORD 12 <SQL_VARCHAR> /* this is the SQL Datatype */
SQLULEN 10
SWORD 0
PTR 0x00184BA8
SQLLEN 520
SQLLEN * 0x00184B90
The described behaviour causes a problem with the used database (Ingres in
this case).
I'm wondering why the ODBC Adapter is using SQL_VARCHAR, even though the
OdbcParameter is constructed using
OdbcParameter("name",OdbcType.NVarChar,10,"name");
Is there an error in the small example program?
Or is this a problem with the Ingres ODBC driver not telling .NET which
datatypes it supports?
Or is this a problem within the .NET ODBC Adapter?
Any idea is appreciated.
Thanks
Kris
A simple program does an insert into table "u" having one nvarchar column
"name", the actual value is passed as a parameter.
So the code is quite simple:
....
OdbcConnection conn = new OdbcConnection("DSN=xxx");
OdbcCommand command;
string s;
....
OdbcParameter p = new OdbcParameter("name",OdbcType.NVarChar,10,"name");
p.OdbcType = OdbcType.NVarChar;
string sql = "insert into u (name) values (?)";
s = "A";
p.Value=s ;
conn.Open ();
command = new OdbcCommand (sql,conn);
command.Parameters.Add (p);
command.ExecuteNonQuery ();
....
The problem here is, that the .NET ODBC defines the SQL datatype as
SQL_VARCHAR when calling SQLBindParameter(), while I would expect
SQL_WVARCHAR.
This can be seen in the ODBC trace:
260-e90 ENTER SQLBindParameter
HSTMT 00F31A10
UWORD 1
SWORD 1 <SQL_PARAM_INPUT>
SWORD -8 <SQL_C_WCHAR>
SWORD 12 <SQL_VARCHAR> /* this is the SQL Datatype */
SQLULEN 10
SWORD 0
PTR 0x00184BA8
SQLLEN 520
SQLLEN * 0x00184B90
The described behaviour causes a problem with the used database (Ingres in
this case).
I'm wondering why the ODBC Adapter is using SQL_VARCHAR, even though the
OdbcParameter is constructed using
OdbcParameter("name",OdbcType.NVarChar,10,"name");
Is there an error in the small example program?
Or is this a problem with the Ingres ODBC driver not telling .NET which
datatypes it supports?
Or is this a problem within the .NET ODBC Adapter?
Any idea is appreciated.
Thanks
Kris