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