Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将转换为字节数组的位图存储在SQL Server的Varbinary(MAX)或Image数据类型中_C#_Sql Server_Bytearray_Varbinary_Varbinarymax - Fatal编程技术网

C# 将转换为字节数组的位图存储在SQL Server的Varbinary(MAX)或Image数据类型中

C# 将转换为字节数组的位图存储在SQL Server的Varbinary(MAX)或Image数据类型中,c#,sql-server,bytearray,varbinary,varbinarymax,C#,Sql Server,Bytearray,Varbinary,Varbinarymax,我想将映像存储在SQL Server数据库中。我已将图像转换为字节数组,数据库中列的数据类型为varbinary(MAX),但即使我将其类型更改为image,它也不起作用,但我得到了相同的结果 我关注了stackoverflow、code project、dream in code中的许多链接,但找不到我的解决方案,因为我的代码用于在数据库中插入字节数组 string query = @"INSERT INTO myTable (ID, byteArray, DateTime) VALUES (

我想将映像存储在SQL Server数据库中。我已将图像转换为字节数组,数据库中列的数据类型为
varbinary(MAX)
,但即使我将其类型更改为
image
,它也不起作用,但我得到了相同的结果

我关注了stackoverflow、code project、dream in code中的许多链接,但找不到我的解决方案,因为我的代码用于在数据库中插入字节数组

string query = @"INSERT INTO myTable (ID, byteArray, DateTime) VALUES (@ID, @byteArray, @datetime)";

try
{
      command = new SqlCommand(query, base.conn);
      command.Parameters.AddWithValue("@ID", id);
      command.Parameters.AddWithValue("@byteArray", ss); // ss is byte[] from arguments
      command.Parameters.AddWithValue("@datetime", DateTime.Now);

      base.Open();
      if (command.ExecuteNonQuery() > 0)
      {
            base.Close();
            return true;
      }
      else
      {
             base.Close();
             return false;
      }
}
catch (SqlException ex)
{
      base.Close();
      return false;
}
我也试过了

command = new SqlCommand(query, base.conn);
command.Parameters.Add("@ID", id);
command.Parameters.Add("@byteArray", ss); // ss is byte[] from arguments
command.Parameters.Add("@datetime", DateTime.Now);
以及它将存储在数据库中的东西


但是,当某些二进制数据(如图片)存储在第三列中时,它将在第三列中显示值,即
这是什么??

。这是按设计工作的


在SQLServerManagementStudio中实际上看不到图片本身。我很确定你的代码运行得很好——只是你对Management Studio的期望太高了……

@marc_s,这就是答案,如果你按原样发布,我会对它进行升级。但我如何检索它以便将其转换为Bitmap@assassino:您只需使用标准查询
选择
数据,并将其作为字节数组/流返回到.NET应用程序,然后可以将其馈送到
位图
类中。。。但这又是一个完全不同的问题!