【问题标题】:how to read varbinary max sql server [duplicate]如何读取 varbinary max sql server [重复]
【发布时间】:2015-08-23 15:24:00
【问题描述】:

我有这个问题:

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

【问题讨论】:

  • 可能你的表被截断了?

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


【解决方案1】:

您不能将NULL&lt;&gt; 运算符进行比较,使用IS 运算符来验证NULL

where userID = @userid AND avatar is not null

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 2014-07-29
    • 2014-07-26
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    相关资源
    最近更新 更多