我有这个问题:
CREATE PROCEDURE [dbo].[spGetUserAvatar]
( @userid int)
AS
BEGIN
select avatar
from t_user
where (userID = @userid) AND (avatar<>null)
end
以及执行此查询的C#代码:
string ConnectionString = SafaConnectionString.ConnectionString;
SqlConnection Connection = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand("spGetUserAvatar", Connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@userid", userid);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter();
try
{
cmd.Connection = Connection;
Connection.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
if (dt.Rows.Count > 0)
return dt;
else
return null;
}
它工作正常,但现在返回dt.Rows.Count == 0
。如果是,
t_users.avatar不是空的。
我的查询错了吗?
答案 0 :(得分:0)
您无法将NULL
与<>
运算符使用IS
运算符进行比较,以验证NULL
值
where userID = @userid AND avatar is not null