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 获取二进制数据
基础教程推荐
- 获取C#保存对话框的文件路径 2022-01-01
- 如果条件可以为空 2022-01-01
- 将数据集转换为列表 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
