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 获取二进制数据
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
