-1
Private Sub UpdatePicture()
Dim str As String
str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=UsersDB.accdb"
cn = New OleDbConnection(str)
cn.Open()
Dim ms As New MemoryStream()
Dim arrimage() As Byte
If (PictureBox1.Image IsNot Nothing) Then
PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
arrimage = ms.GetBuffer
ms.Close()
End If
With cmd
.Connection = cn
.CommandText = "UPDATE Users set Picture = @img where StudentNumber " & TextBox1.Text & ""
.Parameters.Add("@img", OleDbType.Binary).Value = IIf(PictureBox1.Image IsNot Nothing, arrimage, DBNull.Value)
'con.Open()
i = .ExecuteNonQuery()
.Dispose()
cn.Close()
If (i > 0) Then
MsgBox("Save Successs!")
End If
End With
con.Close()
End Sub
有人能给我的代码显示/检索或获取图像从我的PictureBox1.Image从Access数据库根据此代码?如何显示/检索或从Access数据库获取图像到PictureBox?
请张贴代码显示您如何尝试解决您的问题。 StackOverflow不是给你的代码网站。请提出问题并在提问时遵循以下建议:http://stackoverflow.com/help/how-to-ask和http://stackoverflow.com/help/mcve – jordanhill123 2014-09-20 02:12:39
您可以使用例如' PictureBox1.Image.Save()''您可以从中获取要存储的字节。要检索,使用'PictureBox1.Image = Image.FromXXX()'方法将二进制数据读入图像。 – Basic 2014-09-20 02:16:24
[从访问数据库检索图片]的可能的重复(http://stackoverflow.com/questions/20890646/retrieve-picture-from-access-database) – Plutonix 2014-09-20 11:26:15