值类型与列类型不匹配不能存储在PICTURE列中。预期的类型是Byte []。 [英] Type of value has a mismatch with column typeCouldn't store in PICTURE Column. Expected type is Byte[].

查看:102
本文介绍了值类型与列类型不匹配不能存储在PICTURE列中。预期的类型是Byte []。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好伙伴们

我是vb的新人

i已经能够在一个访问数据库中保存图片和其他数据,并且能够在图片框中显示它,但我无法编辑图片,我可以编辑所有其他数据但是当涉及到图片时它会给我这个错误,

值的类型与列类型不匹配不能存储< ; PICTURE列中的; system.drawing.bitmap>。预期的类型是Byte []

这里是我的编辑代码



Private Sub btnEdit_Click (ByVal sender As System.Object,ByVal e As System.EventArgs)处理btnEdit.Click

Dim cb As New OleDb.OleDbCommandBuilder(da)

如果inc<> ; -1然后

ds.Tables(hip)。Rows(inc).Item(1)= txtidNumber.Text

ds.Tables(hip)。 Rows(inc).Item(2)= txtFirstName.Text

ds.Tables(hip)。Rows(inc).Item(3)= txtMiddleName.Text

ds.Tables(hip)。Rows(inc).Item(4)= txtSurName.Text

ds.Tables(hip)。Rows(inc).Item(5)= cboGender.Text

ds.Tables(hip)。Rows(inc).Item(6)= txtLocation.Text

ds.Tables(hip)。 Rows(inc).Item(7)= txtPhone.Text

ds.Tables(hip)。Rows(inc).Item(8)= txtEmail.Text

ds.Tables(hip)。Rows(inc).Item(9)= txtNotes.Text

Dim bytes As [Byte]()= ds.Tables(hip)。Rows (inc).Item(10)

Dim ms As New MemoryStream(bytes)

picPhoto.Image = Image.FromStream(ms)

ds.Tables(hip)。Rows(inc).Item(10)= picPhoto.Image ------(ERROR HERE)---va的类型lue与列类型不匹配不能存储< system.drawing.bitmap>在PICTURE专栏中。预期的类型是Byte []

da.Update(ds,hip)

MsgBox(DATA EDITED)

结束If

End Sub

解决方案

错误信息非常明确:值的类型与列类型不匹配存储在PICTURE列中。预期的类型是Byte []

您正在将Image传递给需要字节数组的列。所以尝试将Image转换为字节数组:

  Dim  ms 作为  New  MemoryStream()
picPhoto.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp)
ds.Tables( hip)。Rows(inc).Item( 10 )= ms.ToArray( )


hello fellow coders
am new at vb
i have been able to save a picture and other data, in a access database and am able to display it in the picturebox ,but am unable to Edit the picture,i can edit all the other data but when it comes to pictures it gives me this error,
"Type of value has a mismatch with column typeCouldn't store <system.drawing.bitmap> in PICTURE Column. Expected type is Byte[]"
here's my code for editing

Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
If inc <> -1 Then
ds.Tables("hip").Rows(inc).Item(1) = txtidNumber.Text
ds.Tables("hip").Rows(inc).Item(2) = txtFirstName.Text
ds.Tables("hip").Rows(inc).Item(3) = txtMiddleName.Text
ds.Tables("hip").Rows(inc).Item(4) = txtSurName.Text
ds.Tables("hip").Rows(inc).Item(5) = cboGender.Text
ds.Tables("hip").Rows(inc).Item(6) = txtLocation.Text
ds.Tables("hip").Rows(inc).Item(7) = txtPhone.Text
ds.Tables("hip").Rows(inc).Item(8) = txtEmail.Text
ds.Tables("hip").Rows(inc).Item(9) = txtNotes.Text
Dim bytes As [Byte]() = ds.Tables("hip").Rows(inc).Item(10)
Dim ms As New MemoryStream(bytes)
picPhoto.Image = Image.FromStream(ms)
ds.Tables("hip").Rows(inc).Item(10) = picPhoto.Image------(ERROR HERE)---"Type of value has a mismatch with column typeCouldn't store <system.drawing.bitmap> in PICTURE Column. Expected type is Byte[]"
da.Update(ds, "hip")
MsgBox("DATA EDITED")
End If
End Sub

解决方案

The error message is pretty explicit: "Type of value has a mismatch with column type Couldn't store in PICTURE Column. Expected type is Byte[]"
You are passing an Image to a column that expects an array of bytes. So try converting the Image to a byte array:

Dim ms As New MemoryStream()
picPhoto.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
ds.Tables("hip").Rows(inc).Item(10) = ms.ToArray()


这篇关于值类型与列类型不匹配不能存储在PICTURE列中。预期的类型是Byte []。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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