加载图片时出错 [英] Error loading image
本文介绍了加载图片时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误参数无效
私人 Sub ImageDisplay()
尝试
PictureBox1.Image = Nothing
Dim Scon As 新 SqlConnection( 数据源= xxx;初始目录= xxx; Trusted_Connection = True ; timeout = 100)
Scon.Open()
Dim Scom As 新 SqlCommand( 从table1中选择数据id = 2,Scon) 待更新
尝试
Dim imageData 作为 字节()= DirectCast (Scom.ExecuteScalar(),字节())
如果 不 imageData 什么 然后
使用 ms 作为 新 MemoryStream(imageData, 0 ,imageData.Length)
ms.Write(imageData, 0 ,imageData.Length)
newImage = Image .FromStream(ms, True )
结束 使用
PictureBox1.Image = newImage
结束 < span class =code-keyword>如果
Catch ex As 异常
MessageBox.Show(ex.Message)
结束 尝试
Scon.Close()
Catch ex As 异常
最后
结束 < span class =code-keyword>尝试
结束 Sub
请帮助
解决方案
< blockquote>空间很重要...
Dim Scom 作为 新 SqlCommand( 从table1中选择数据,其中id = 2,Scon)' 待更新
应该是:
Dim Scom As 新 SqlCommand( 从table1中选择数据,其中id = 2,Scon)' 待更新
Error parameter not valid
Private Sub ImageDisplay()
Try
PictureBox1.Image = Nothing
Dim Scon As New SqlConnection("Data Source=xxx; Initial Catalog=xxx; Trusted_Connection=True; timeout = 100")
Scon.Open()
Dim Scom As New SqlCommand("Select datafrom table1 where id=2", Scon) 'to be updated
Try
Dim imageData As Byte() = DirectCast(Scom.ExecuteScalar(), Byte())
If Not imageData Is Nothing Then
Using ms As New MemoryStream(imageData, 0, imageData.Length)
ms.Write(imageData, 0, imageData.Length)
newImage = Image.FromStream(ms, True)
End Using
PictureBox1.Image = newImage
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Scon.Close()
Catch ex As Exception
Finally
End Try
End Sub
please help
解决方案
Spaces matter...
Dim Scom As New SqlCommand("Select datafrom table1 where id=2", Scon) 'to be updatedShould be:
Dim Scom As New SqlCommand("Select data from table1 where id=2", Scon) 'to be updated
这篇关于加载图片时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文