Vb.net &引用;“系统.图纸.图像”;无法转换为';一维阵列

Vb.net &引用;“系统.图纸.图像”;无法转换为';一维阵列,vb.net,Vb.net,我正在用Access数据库在VB.Net中制作一张带有图片的注册表。利用下面的代码,我得到一个错误 Me.Student_instructorTableAdapter.Insert(txtname,txtpass, ***PictureBox1.Image***) Me.Student_instructorTableAdapter.Fill(Me.DatabaseDataSet4.student_instructor) MsgBox("Successfully added", MsgBoxSt

我正在用Access数据库在VB.Net中制作一张带有图片的注册表。利用下面的代码,我得到一个错误

Me.Student_instructorTableAdapter.Insert(txtname,txtpass, ***PictureBox1.Image***)
Me.Student_instructorTableAdapter.Fill(Me.DatabaseDataSet4.student_instructor)

MsgBox("Successfully added", MsgBoxStyle.Information)
PictureBox1.Image
正在保存到Access数据库(“picture”)中,该数据库引发错误:

无法将“System.Drawing.Image”转换为“一维数组”

当我调用
Insert
以避免异常时,应该使用什么来代替
PictureBox1.Image

我们需要完整的异常消息来准确地知道它期望的是什么(什么的一维数组?),很可能是一个字节数组

如果是这样,您可以将图像转换为如下所示的字节数组

Public Function ImageToByteArray(imageIn As System.Drawing.Image) As Byte()
    Dim ms As New MemoryStream()
    imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
    Return ms.ToArray()
End Function
Public Function byteArrayToImage(byteArrayIn As Byte()) As Image
    Dim ms As New MemoryStream(byteArrayIn)
    Dim returnImage As Image = Image.FromStream(ms)
    Return returnImage
End Function
您可以将字节数组转换回如下图像

Public Function ImageToByteArray(imageIn As System.Drawing.Image) As Byte()
    Dim ms As New MemoryStream()
    imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
    Return ms.ToArray()
End Function
Public Function byteArrayToImage(byteArrayIn As Byte()) As Image
    Dim ms As New MemoryStream(byteArrayIn)
    Dim returnImage As Image = Image.FromStream(ms)
    Return returnImage
End Function
更多信息

我不熟悉access数据类型,因此它可能直接支持图像。如果是这样,您需要确保为该列/字段选择了正确的数据类型


顺便说一下,如果你不需要,不要使用Access(或者至少是存储引擎/ Jet)来进行新的项目——它是缓慢的,不可靠的,超过10个用户,并且有严重的安全问题。如果你不想要一个完整的SQL Server数据库,请考虑SQL紧凑版(CE)。或者SQL Express。

不,您几乎调用的是需要图像流,该图像流可以转换为字节[],并进入类型为image的列中。