SQL Server Compact Edition ISNULL(sth, ' ') 返回一个布尔值? [英] SQL Server Compact Edition ISNULL(sth, ' ') returns a boolean value?

查看:26
本文介绍了SQL Server Compact Edition ISNULL(sth, ' ') 返回一个布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Accounts 表,其中包含 name、passwordemail 列.它们都是 nvarchar 类型.我写了一个像

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 + "'"

我将电子邮件阅读为 reader.getString(2),因为它是 nvarchar.

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

正如我从互联网上看到的,如果 email 为 NULL,那么它应该返回 eeee.但它说System.boolean 不能转换为System.String.

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?

推荐答案

根据 this ISNULL 未在 SQL Server CE 中实现.但是,我希望看到语法错误.

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

解决方法:您可以使用 CASE WHEN email IS NULL THEN 'eeee' ELSE email ENDCOALESCE.最好是后者.

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.

这篇关于SQL Server Compact Edition ISNULL(sth, ' ') 返回一个布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆