如何读取varbinary max sql server

时间:2015-08-23 15:24:00

标签: c# asp.net sql-server sql-server-2012

我有这个问题:

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不是空的。 我的查询错了吗?

1 个答案:

答案 0 :(得分:0)

您无法将NULL<>运算符使用IS运算符进行比较,以验证NULL

where userID = @userid AND avatar is not null
相关问题