Getting binary data using SqlDataReader(使用 SqlDataReader 获取二进制数据)
问题描述
我有一个名为 Blob (Id (int), Data (Image)) 的表.我需要使用 SqlDataReader 来获取该图像数据.请注意,我不想将 Response.Binarywrite() 数据发送到浏览器.我只需要将二进制数据作为 byte[] 就可以将其用于某些内部操作.我能想到的唯一方法是使用 SqlDataReader 获取 id,然后再次使用 SqlCommand.ExecuteScalar() 将其作为给定 id 的 byte[] 获取.我可以只使用 SqlDataReader (SqlCommand.ExecuteReader) 将图像数据作为字节 [] 获取吗?我错过了什么吗?
I have a table named Blob (Id (int), Data (Image)). I need to use SqlDataReader to get that image data. Note that I dont want to Response.Binarywrite() the data to the browser. I just need that binary data as byte[] to use the same for some internal operations. Only way I can think of is getting id using SqlDataReader and the again use SqlCommand.ExecuteScalar() to get that as byte[] for a given id. Can I use just the SqlDataReader (SqlCommand.ExecuteReader) to get that image data as byte[]? Am I missing anything?
推荐答案
你应该可以通过:(byte[])reader["Data"]
.
另请注意,image
数据类型已弃用,并将在 SQL Server 的未来版本中删除;改用 varbinary(max)
.
Also note that the image
data type is deprecated, and will be removed in a future version of SQL Server; use varbinary(max)
instead.
这篇关于使用 SqlDataReader 获取二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 SqlDataReader 获取二进制数据


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01