OLEDB comparison problem nvarchar against ntext (S

2019-08-17 01:51发布

I have table Tbl1( SomeName nvarchar(64) )

Over OLEDB I'm trying to select SELECT 1 FROM Tbl1 WHERE SomeName = ?

binding 3 character unicode as parameter causes: DB_E_ERRORSINCOMMAND(0x80040E14L) "The data types nvarchar and ntext are incompatible in the equal to operator"

I have already tried following input bindings:

1) ...
    currentBind.wType         = DBTYPE_VARIANT;
    currentBind.cbMaxLen      = 20
    // where data points to valid VT_BSTR allocated by SysAllocString
...
2) ...
    currentBind.wType         = DBTYPE_WSTR;
    currentBind.cbMaxLen      = 20
    // where data points to valid VT_BSTR allocated by SysAllocString
...

In any way SQLServer treates this parameter as ntext. Any suggestions? Thank you in advance.

1条回答
等我变得足够好
2楼-- · 2019-08-17 02:37

Quick and dirty hack: change the query.

It should look like this:

SELECT 1 FROM Tbl1 WHERE SomeName = cast(? as nvarchar(64))

Next. I'd profile the code to see what does you provider actually generates in terms of SQL statements. The results could cast some light on the question who's guilty in wrong parameter typing.

查看更多
登录 后发表回答