这几天一直在搞一个,图片的存储和显示的小系统,但是进展很小,图片存储在SQL SERVER 中,现在要完成的是,上传——存储——显示
主要代码如下:
connection = New SqlConnection("Server=ripple;Uid=sa;Pwd=11;database=ww")
Dim sql1 As String = "select photo from person where name='" & name & "'"
command = New SqlCommand(sql1, connection)
connection.Open()
datareader = command.ExecuteReader()
While (datareader.Read)
Dim byt() As Byte
Try
Dim o As Object = datareader("photo")
If o Is Nothing Then
Else
byt = o
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim ms As MemoryStream
Dim bm As Bitmap
Try
ms = New MemoryStream(byt)
bm = New Bitmap(ms) ‘出错“无效参数”
Catch ex As Exception
If Not ms Is Nothing Then ms.Close()
Finally
If Not ms Is Nothing Then ms.Close()
End Try
If bm Is Nothing Then
Else
Me.UltraPictureBox1.Image = bm
Me.UltraPictureBox1.Refresh()
'ms.Close()
End If
End While
datareader.Close()
connection.Close()
请高手帮忙!谢谢!!
浙公网安备 33010602011771号