很奇怪的一个问题,为什么同样的程序将图像读入数据库,再从数据库读出来,显示出来,对jpg,bmp同样的图标文件png格式可以而ico格式的就说gdi+发生一般性错误?这是怎么回事?下面是代码: Imports System.IOPublic Class Form1 Inherits System.Windows.Forms.Form Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim fs As FileStream = New FileStream("E:\工程\图片2\11.png", FileMode.Open, FileAccess.ReadWrite) Dim bt(fs.Length) As Byte fs.Read(bt, 0, fs.Length) fs.Close() fs = Nothing Dim sqlConn As SqlClient.SqlConnection = New SqlClient.SqlConnection("Server=(local);User Id=sa;Password=sa;Database=picture") sqlConn.Open() Dim sqlCmd As New SqlClient.SqlCommand("sp_InsertImage", sqlConn) sqlCmd.CommandType = CommandType.StoredProcedure sqlCmd.Parameters.Add("@img", SqlDbType.Image).Value = bt sqlCmd.ExecuteNonQuery() sqlCmd = Nothing sqlConn.Close() sqlConn = Nothing MsgBox("图片插入成功", MsgBoxStyle.Information) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim sqlConn As SqlClient.SqlConnection = New SqlClient.SqlConnection("Server=(local);User Id=sa;Password=sa;Database=picture") sqlConn.Open() Dim sqlCmd As New SqlClient.SqlCommand("SELECT img FROM test WHERE t_ID=66", sqlConn) sqlCmd.CommandType = CommandType.Text Dim bt() As Byte = sqlCmd.ExecuteScalar() If Not bt Is Nothing Then If bt.Length > 0 Then Dim fs As MemoryStream = New MemoryStream(bt) pbReview.Image = Image.FromStream(fs) fs.Close() fs = Nothing Else MsgBox("无图片") End If Else MsgBox("无数据") End If sqlCmd = Nothing sqlConn.Close() sqlConn = Nothing End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Dispose(True) End Sub End Class
Imports System.IOPublic Class Form1 Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fs As FileStream = New FileStream("E:\工程\图片2\11.png", FileMode.Open, FileAccess.ReadWrite)
Dim bt(fs.Length) As Byte
fs.Read(bt, 0, fs.Length)
fs.Close()
fs = Nothing
Dim sqlConn As SqlClient.SqlConnection = New SqlClient.SqlConnection("Server=(local);User Id=sa;Password=sa;Database=picture")
sqlConn.Open() Dim sqlCmd As New SqlClient.SqlCommand("sp_InsertImage", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.Add("@img", SqlDbType.Image).Value = bt
sqlCmd.ExecuteNonQuery()
sqlCmd = Nothing
sqlConn.Close()
sqlConn = Nothing
MsgBox("图片插入成功", MsgBoxStyle.Information)
End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlConn As SqlClient.SqlConnection = New SqlClient.SqlConnection("Server=(local);User Id=sa;Password=sa;Database=picture")
sqlConn.Open()
Dim sqlCmd As New SqlClient.SqlCommand("SELECT img FROM test WHERE t_ID=66", sqlConn)
sqlCmd.CommandType = CommandType.Text Dim bt() As Byte = sqlCmd.ExecuteScalar()
If Not bt Is Nothing Then
If bt.Length > 0 Then
Dim fs As MemoryStream = New MemoryStream(bt)
pbReview.Image = Image.FromStream(fs)
fs.Close()
fs = Nothing Else
MsgBox("无图片")
End If
Else
MsgBox("无数据")
End If sqlCmd = Nothing
sqlConn.Close()
sqlConn = Nothing End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Dispose(True)
End Sub
End Class