SQL Server Compact Edition ISNULL(sth, ' ') returns a boolean value?

守給你的承諾、 提交于 2019-11-28 08:07:37

问题


I have an Accounts table with columns name, password and email. They are all type nvarchar. I wrote a query like

SELECT name, password, ISNULL(email, 'eeee') 
FROM Accounts 
WHERE name = '" + textBox1.Text + "' AND password ='" + textBox2.Text + "'"

I read the email as reader.getString(2) since it is nvarchar.

As I read from the internet, if email is NULL, then it should return eeee. But it says System.boolean can not be translated to System.String.

How can I correct this? Why does it return a boolean value?


回答1:


According this this ISNULL is not implemented in SQL Server CE. I would expect to see a syntax error raised, however.

Workaround: you can use CASE WHEN email IS NULL THEN 'eeee' ELSE email END or COALESCE. Preferably the latter.

Also use parameterised queries. If you don't know why you should, learn.



来源:https://stackoverflow.com/questions/5890970/sql-server-compact-edition-isnullsth-returns-a-boolean-value

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