从数据库文件加载字节数据 [英] Loading Byte data from database file

查看:88
本文介绍了从数据库文件加载字节数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用以下代码从数据库获取数据并加载到图片框

Hi,
I am using following code to get data from database and load to picture box

Dim vrPicFromDB = IO.File.ReadAllBytes(DsPic.tblPicTest.Item("Picture"))
        Dim ms As New MemoryStream(vrPicFromDB)
        PictureBox1.Image = Image.FromStream(ms)



它在语句的DsPic.tblPicTest.Item("Picture"))部分给出错误.
我也尝试过



It gives error on DsPic.tblPicTest.Item("Picture")) portion of the statement.
I also tried

CByte(DsPic.tblPicTest.Item("Picture")))


但它给出了相同的错误.

请告知如何修复.
谢谢
Furqan


but it gives the same error.

Please advise how to fix it.
Thanks
Furqan

推荐答案

等待,您提到您正在尝试从数据库读取字节.那么File在这里做什么?

IO.File.ReadAllBytes

如果您已经将数据保存为二进制格式,则可能根本不需要任何转换.
wait, you mentioned that you are trying to read bytes from database. What is File doing here then?

IO.File.ReadAllBytes

If you already saved your data in binary format, you might not need any conversion at all.


首先,
的参数 IO.File.ReadAllBytes是文件路径.如果您以字节为单位存储图像,则不需要它.

其次,IO.File.ReadAllBytes返回一个字节数组.没有一个字节.这就是CByte无法正常工作的原因.
如果您在理解此类内置函数时遇到麻烦,请尝试使用google或MSDN寻求帮助.例如,这是 ReadAllBytes [ ^ ].

尝试将vrPicFromDB声明为字节数组,然后将其设置为等于DsPic.tblPicTest.Item("Picture").
First of all, the parm for
IO.File.ReadAllBytes is a file path. If you are storing your image in bytes you don''t need this.

Secondly, IO.File.ReadAllBytes Returns a Byte Array. Not a byte. That is why CByte doesn''t work.

If you are having trouble understanding built in functions like that, try google or MSDN for help. For example, here is the documentation on ReadAllBytes[^].

Try declaring vrPicFromDB as a byte array and then just set it equal to DsPic.tblPicTest.Item("Picture").


这篇关于从数据库文件加载字节数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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