开发者

Reading binary data from SQL Server CE database in C#

I have an image stored in my SQL Server CE database as binary data. The column is defined as an 'Image'. I would like to retrieve this data now back into an Image and display it in my picturebox control. I don't know exactly how to do this and I tried searching online, but there were no good articles explaining how to go about doing this.

So far I have the following code:

开发者_开发技巧
            if (dataReader.GetValue(3) != null)
            {
              // Retrieve binary data
              // create the image and add it to the picturebox.
            }

I'm assuming I have to use the following method:

dataReader.GetBytes()

I just don't know how where to start with this. Any comments would be helpful.


Assuming GetBytes() returns a byte array you can try something like this:

MemoryStream ms = new MemoryStream(dataReader.GetBytes());
Image img = Image.FromStream(ms);

// then assign img to your picture box

I've done this but not for a while, so you may have to do some of your own digging to complete this answer. Look at the static factory methods ("FromXYZ") of the Image class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜