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

查看:94
本文介绍了获得使用SqlDataReader的二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为一滴表(ID(INT),数据(图像))。我需要使用SqlDataReader对象来获取图像数据。注意,我不想Response.Binarywrite()的数据到浏览器。我只需要二进制数据为byte []的使用相同的一些内部操作。只有这样我能想到的是越来越ID使用SqlDataReader的和再次使用SqlCommand.ExecuteScalar()来获取作为字节[]为给定ID。我可以只使用SqlDataReader的(SqlCommand.ExecuteReader)来获取图像数据的byte []?我缺少什么?

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?

推荐答案

您应该可以用得到它:(字节[])reader.Items [数据]

You should be able to get it via: (byte[])reader.Items["Data"].

另外请注意,图片数据类型是去precated,并且将在SQL Server的未来版本中删除;使用 VARBINARY(最大)代替。

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天全站免登陆