将PictureBox数据绑定到SQL Server ... [英] Databind a PictureBox to a SQL Server...

查看:47
本文介绍了将PictureBox数据绑定到SQL Server ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将一个Picturebox数据绑定到一个SQL Server。

我有一个打字的数据集DSBoernekirken1

它有一个名为tpersoner的表使用列照片

我当然希望使用

属性将图像直接绑定到tpersoner.photo(就像我使用文本字段一样),但是这个似乎没有

可能。

然后我搜索了一些新闻组和知识库,发现了以下

代码:

Sub ShowPicture()

''从数据库中获取数据并将其放入数据集中

OleDbDataAdapter1.Fill(DataSet11)

''获取字节数组并将其转换为图片

Dim arrPicture()As Byte = CType(DataSet11.Photos.picture,Byte())

Dim ms如新的IO.MemoryStream(arrPicture)

''在图片框中显示图片

PictureBox1.Image = Image.FromStream(ms)

结束子


我将其更改为

Dim arrPicture()As Byte = CType(DsBoerneKirken1.tPersoner.PhotoColumn,

Byte ())''Intellisense只允许Photocolumn,而不是Photo。然后我收到

错误System.data.Datacolumn类型的值无法转换为

字节数组的字节数

''我也试过

''Dim arrPicture2()As Byte =

CType(DsBoerneKirken1.tPersonerDataTable.PhotoColu mn,Byte())

''Dim arrPicture3()As Byte = CType(DsBoerneKirken1.tPersonerDataTable.Photo,

Byte())

''Dim arrPicture4()As Byte = CType (DsBoerneKirken1.tPersoner.Photo,Byte())


Dim ms As New IO.MemoryStream(arrPicture)

''显示图片框中的图片

PictureboxPhoto.Image = Image.FromStream(ms)


谁能告诉我我做错了什么?


*****''

我也找到了


Dim bytBLOBData()As Byte = ds.Tables(" BLOBTest")。行( c -

1)(BLOBData)

Dim stmBLOBData As New MemoryStream(bytBLOBData)

picBLOB.Image = Image.FromStream(stmBLOBData)


我改为

Dim bytBLOBData()As Byte = DsBoerneKirken1.tPersoner.PhotoColumn

Dim stmBLOBData As New MemoryStream(bytBLOBData)

PictureboxPhoto.Image = Image.FromStream(stmBLOBData)

大致相同的错误。


最好的问候


Jan

Hi
I would like to databind a Picturebox to a SQL Server.
I have a typed Dataset "DSBoernekirken1"
It has a table named "tpersoner" with a column "Photo"
I of course would like to bind the image directly to tpersoner.photo using
Properties (like I do with text fields), but this does not seem to be
possible.
Then I searched some news groups and Knowledgebase and found the following
code:
Sub ShowPicture()
''get the data from the database and put it in the dataset
OleDbDataAdapter1.Fill(DataSet11)
''get the byte array and convert it to a picture
Dim arrPicture() As Byte = CType(DataSet11.Photos.picture, Byte())
Dim ms As New IO.MemoryStream(arrPicture)
''show the picture in the picturebox
PictureBox1.Image = Image.FromStream(ms)
End Sub

I changed this to
Dim arrPicture() As Byte = CType(DsBoerneKirken1.tPersoner.PhotoColumn,
Byte()) '' Intellisense only allows Photocolumn, not Photo. Then I receive
the error "Value of type System.data.Datacolumn can not be converted to
1-dimensional array of Byte"
'' I have also tried
''Dim arrPicture2() As Byte =
CType(DsBoerneKirken1.tPersonerDataTable.PhotoColu mn, Byte())
''Dim arrPicture3() As Byte = CType(DsBoerneKirken1.tPersonerDataTable.Photo,
Byte())
'' Dim arrPicture4() As Byte = CType(DsBoerneKirken1.tPersoner.Photo, Byte())

Dim ms As New IO.MemoryStream(arrPicture)
''show the picture in the picturebox
PictureboxPhoto.Image = Image.FromStream(ms)

Can anyone tell me what I am doing wrong?

*****''
I also found

Dim bytBLOBData() As Byte = ds.Tables("BLOBTest").Rows(c -
1)("BLOBData")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
picBLOB.Image = Image.FromStream(stmBLOBData)

Which I changed to
Dim bytBLOBData() As Byte = DsBoerneKirken1.tPersoner.PhotoColumn
Dim stmBLOBData As New MemoryStream(bytBLOBData)
PictureboxPhoto.Image = Image.FromStream(stmBLOBData)
With about the same error.

Best regards

Jan

推荐答案

你好Jan,


我认为它与你使用数据集的方式有关
Hi Jan,

I think it has to do with the way you use the dataset
''Dim arrPicture3()As Byte = CType(.......... ................
DsBoerneKirken1.tPersonerDataTable.Photo
''Dim arrPicture3() As Byte = CType(..........................
DsBoerneKirken1.tPersonerDataTable.Photo




也许它可以像

DsBoerneKirken1.tPersonerDataTabele.rows(0)(照片),而不是数据集中的第一张图片



但如果不起作用,你可以试试

DsBoerneKirken1.tables(0).rows(0)(照片)


其余的是只要我能看到就好了。


我希望这有点帮助吗?


Cor



Maybe it can be something like
DsBoerneKirken1.tPersonerDataTabele.rows(0)("photo ") and that is than the
first picture in your dataset.

But if that not works, you can try
DsBoerneKirken1.tables(0).rows(0)("photo")

The rest was as far as I could see like has to be.

I hope this helps a little bit?

Cor


Hi Cor

感谢您的回答

因此,如果我想要显示当前行的图片,我必须

使我自己的指针插入... rows(CurrentRow)代码?


我收到错误

"无效使用的参数当我使用行(0)。


这是我的确切代码:

Dim arrPicture()As Byte = CType(DsBoerneKirken1.tPersoner.Rows(0 )(照片),

Byte())

Dim ms As New IO.MemoryStream(arrPicture)

试试

PictureboxPhoto.Image = Image.FromStream(ms)

Catch ex As Exception

MsgBox(ex.Message)

结束试试


这是PictureboxPhoto.Image = Image.FromStream(ms)线路

抛出异常。


祝你好运


Jan


Cor < no*@non.com> skrev i en meddelelse

新闻:3f *********************** @ reader20.wxs.nl ...
Hi Cor
Thanks for answering
So if I would like the picture from the current row to be shown do I have to
make my own pointer to insert in the ...rows(CurrentRow) code?

I receive an error
"Invalid Parameter Used" when I use rows(0).

Here is my exact code:
Dim arrPicture() As Byte = CType(DsBoerneKirken1.tPersoner.Rows(0)("photo"),
Byte())
Dim ms As New IO.MemoryStream(arrPicture)
Try
PictureboxPhoto.Image = Image.FromStream(ms)
Catch ex As Exception
MsgBox(ex.Message)
End Try

It is the "PictureboxPhoto.Image = Image.FromStream(ms)" line
that throws the exception.

Best regards

Jan

"Cor" <no*@non.com> skrev i en meddelelse
news:3f***********************@reader20.wxs.nl...
你好Jan,

我认为这与你使用数据集的方式有关
Hi Jan,

I think it has to do with the way you use the dataset
''Dim arrPicture3()As Byte = CType(..........................
DsBoerneKirken1.tPersonerDataTable.Photo
''Dim arrPicture3() As Byte = CType(..........................
DsBoerneKirken1.tPersonerDataTable.Photo



也许它可能类似于DsBoerneKirken1.tPersonerDataTabele.rows(0)(照片),而不是数据集中的第一张图片。

但如果是这样的话不行,你可以试试
DsBoerneKirken1.tables(0).rows(0)(照片)

剩下的就是我所能看到的一样。

我希望这有点帮助吗?

Cor



Maybe it can be something like
DsBoerneKirken1.tPersonerDataTabele.rows(0)("photo ") and that is than the
first picture in your dataset.

But if that not works, you can try
DsBoerneKirken1.tables(0).rows(0)("photo")

The rest was as far as I could see like has to be.

I hope this helps a little bit?

Cor



你好Jan,


我的照片就是一个例子,也许它是一样的,但是当我查看你的

代码时,它可能是一个upercase。 (这是你照片的名字

项目在您的SQL数据库中(或您在SQL中命名的方式选择

脚本)。


Cor
Hi Jan,

My "photo" was an example, maybe it is the same, but when I look at your
code it is then probably with an upercase. (it is the name of your photo
item in your SQL database (or the way you have named in your SQL select
script).

Cor
这是我的确切代码:
Dim arrPicture()As Byte =
CType(DsBoerneKirken1.tPersoner.Rows(0)(photo),Byte( ))
Dim ms As New IO.MemoryStream(arrPicture)
尝试
PictureboxPhoto.Image = Image.FromStream(ms)
Catch ex As Exception> MsgBox(ex 。消息)
结束尝试
Here is my exact code:
Dim arrPicture() As Byte = CType(DsBoerneKirken1.tPersoner.Rows(0)("photo"), Byte())
Dim ms As New IO.MemoryStream(arrPicture)
Try
PictureboxPhoto.Image = Image.FromStream(ms)
Catch ex As Exception
MsgBox(ex.Message)
End Try



这篇关于将PictureBox数据绑定到SQL Server ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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