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

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/288022.html

(0)
上一篇 2022年9月7日
下一篇 2022年9月7日

相关推荐

发表回复

登录后才能评论