C/C++教程

PictureBox 从数据库加载图片照片

本文主要是介绍PictureBox 从数据库加载图片照片,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Private Sub PAPHOTO_SEL()
Try
Dim objCon As SqlConnection
Dim objCmd As SqlCommand
'打开数据库
objCon = New SqlConnection(PA001H_INSERT.strConn)
objCon.Open()
'定义SQL字符串
Dim SQL_String As String
SQL_String = "select top 1 pa_photo from LJPA005H WHERE pa_no='" & Me.TB_PANO.Text & "' order by uid desc"
'执行操作
objCmd = New SqlCommand(SQL_String, objCon)
'objCmd.CommandTimeout = dbTimeout
objCmd.ExecuteNonQuery()

Dim DataRd As SqlDataReader = objCmd.ExecuteReader
If DataRd.Read Then
Dim da() As Byte
da = DataRd("pa_photo")
Me.PB_PAPHOTO.Image = Bitmap.FromStream(New IO.MemoryStream(da))
Else
'Me.TxtPictureURL.Text = "数据库中没有图片!"
Me.PB_PAPHOTO.Image = Global.LJPA001H.My.Resources.Resources.noimage
End If
DataRd.Close()
objCon.Close()
Catch ex As Exception
MessageBox.Show(Err.Description)
End Try

End Sub

这篇关于PictureBox 从数据库加载图片照片的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!