数据库
首页 > 数据库> > 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

标签:Me,Dim,String,数据库,DataRd,objCmd,PictureBox,objCon,加载
来源: https://www.cnblogs.com/beichengshiqiao/p/16662978.html