使用 SqlDataReader 获取二进制数据 [英] Getting binary data using SqlDataReader

查看:18
本文介绍了使用 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 获取二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆