Vb.net GDI+将Picturebox保存到ole数据库时发生一般性错误
我正在尝试将picturebox保存到ole数据库中 这是我的密码:Vb.net GDI+将Picturebox保存到ole数据库时发生一般性错误,vb.net,oledb,Vb.net,Oledb,我正在尝试将picturebox保存到ole数据库中 这是我的密码: Dim stream As New IO.MemoryStream PictureBox1.Image.Save(stream, Imaging.ImageFormat.Jpeg) Try Dim query As String = "INSERT INTO Guestinfo ([GuestName],[Phone],[Idofguest],[Room],[Arrival],[Checkout],[Address],
Dim stream As New IO.MemoryStream
PictureBox1.Image.Save(stream, Imaging.ImageFormat.Jpeg)
Try
Dim query As String = "INSERT INTO Guestinfo ([GuestName],[Phone],[Idofguest],[Room],[Arrival],[Checkout],[Address],[IDImage]) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox5.Text & "','" & DateTimePicker1.Text & "','" & DateTimePicker2.Text & "','" & TextBox4.Text & "',(@IDImage))"
Dim command As New OleDbCommand
With command
.CommandText = query
.Parameters.AddWithValue("@Picture", stream.GetBuffer())
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("Saved Successfully!", MsgBoxStyle.Information)
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
在GDI+中发生的一般错误中,出现以下错误:
PictureBox1.Image.Save(stream, Imaging.ImageFormat.Jpeg)
顺便说一下,我的列类型是Ole对象。
我希望有人能帮助我 此应用程序有一个“打开”按钮,可帮助您使用OpenFileDialog将任何图片文件打开到表单上的PictureBox。您将在禁用的文本框中看到图片文件的路径。单击“更新”按钮时,图片的路径将保存到Access数据库中 按照以下步骤为自己创建一个类似的项目: *创建新的Visual Basic.net项目。从“新建项目”对话框中选择Windows窗体应用程序。请随意命名此应用程序。 *使用以下提到的属性创建以下内容: -表单-名称:示例,文本:FormPictureApplication -PictureBox-名称:PictureBox1,大小模式:StretchImage -按钮-名称:ButtonUpdate,文本:&更新 -按钮-名称:按钮打开,文本:&打开 -TextBox-名称:TextBoxPictureFilePath,已启用:False 双击表单,在公共类{…}的正上方插入以下代码: 导入System.Data.OleDb 导入System.IO 导入Microsoft.Win32 双击按钮打开并插入以下代码: 将img设置为字符串 将myStream设置为流=无 将openFileDialog1变暗为新OpenFileDialog openFileDialog1.InitialDirectory=c:\ openFileDialog1.Filter=无 openFileDialog1.FilterIndex=2 openFileDialog1.RestoreDirectory=True openFileDialog1.FileName= 如果openFileDialog1.ShowDialog=System.Windows.Forms.DialogResult.OK,则 尝试 myStream=openFileDialog1.OpenFile 如果myStream不是什么,那么 TextBoxPictureFilePath.Text= img=openFileDialog1.FileName PictureBox1.Image=System.Drawing.Bitmap.FromFileimg TextBoxPictureFilePath.Text=openFileDialog1.FileName 如果结束 特例 MessageBox.show无法从磁盘读取文件。原始错误:&Ex.消息 最后 如果myStream不是什么,那么 myStream,关闭 如果结束 结束尝试 如果结束 在方便的位置创建Microsoft Access数据库,并将其命名为Databasemikeoe2003PictureApplication.mdb 创建名为Tablemikeoe2003PictureApplication的表,并向其中添加以下列: Id-数据类型:自动编号 PicturePath-数据类型:备忘录作为文件路径有时可能相当长 双击UpdateButton并插入以下代码: 试一试 Dim myConnection作为OLEDB连接 暗淡的myCommand作为OleDbCommand 将mySQLString设置为字符串 myConnection=New-OleDbConnectionProvider=Microsoft.Jet.OLEDB.4.0;数据源=Databasemikeoe2003PictureApplication.mdb; 我的连接,打开 mySQLString=插入到表MikeoE2003PictureApplication PicturePath值“&替换$TextBoxPictureFilePath.Text,,&” myCommand=New-OleDbCommandmySQLString,myConnection myCommand.ExecuteOnQuery PictureBox1.Image=无 TextBoxPictureFilePath.Text= 特例 MessageBox.Showex.Message&-&ex.Source 结束尝试 运行应用程序,它应该可以按需要工作
该代码有几个问题,是否有图像分配给PicBox?您还应该处理MemStream,您需要重置流。在尝试从中读取之前,请使用ToArray not GetBuffer并使用SQL参数:是的,有一个图像分配给picbox,对于dispose和reset,我刚刚添加了它。我希望得到更多帮助@Puroponix我正在通过流直接将扫描图像保存到picturebox中。如果您告诉我如何将扫描图像保存到数据库@CodingSource中,那将非常有帮助