OLEDB comparison problem nvarchar against ntext (SQLServer 2005)

妖精的绣舞 提交于 2019-12-13 04:04:22

问题


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:


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.



来源:https://stackoverflow.com/questions/1232142/oledb-comparison-problem-nvarchar-against-ntext-sqlserver-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!