0
我想检索我保存到我的.mdf数据库中的图像。我需要这些代码才能使我获得数据并将其显示在pictureBox
中。如何检索.mdf sql数据库中的图像在vb 2010
如何从.mdf数据库中检索图像并在pictureBox
的VB应用程序中显示它们?
我想检索我保存到我的.mdf数据库中的图像。我需要这些代码才能使我获得数据并将其显示在pictureBox
中。如何检索.mdf sql数据库中的图像在vb 2010
如何从.mdf数据库中检索图像并在pictureBox
的VB应用程序中显示它们?
试试这个
Dim path As String = (Microsoft.VisualBasic.Left(Application.StartupPath, Len(Application.StartupPath) - 9))
Dim con As New SqlConnection("Data Source=[Server Name];AttachDbFilename=" & _
path & "Database1.mdf;Integrated Security=True;User Instance=True")
Dim cmd As SqlCommand
cmd = New SqlCommand("select photo from Information where name='image1'", con)
Dim imageData As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
If Not imageData Is Nothing Then
Using ms As New MemoryStream(imageData, 0, imageData.Length)
ms.Write(imageData, 0, imageData.Length)
PictureBox1.BackgroundImage = Image.FromStream(ms, True)
End Using
End If