以下是引用有点甜在2018/9/9 16:28:00的发言:
注释掉这段代码测试
Dim cmd As SQLCommand = new SQLCommand()
cmd.ConnectionName = "SqlServerDB"
cmd.CommandText = "select 照片列 from 员工表 where 姓名 = '张三'"
Dim imageByte() As Byte = cmd.ExecuteScalar() '查询数据,并存入字节数组
Dim ms As New IO.MemoryStream(imageByte) '将字节数组转换为二进制流
Dim image As Image = Image.FromStream(ms) '将二进制流转换为图片
e.Form.Controls("PictureBox1").Image = image '显示图片
我本来是在表的currentChanged事件中有如下代码:
If Forms("更改窗口").Opened Then '如果窗口已经打开
Dim pbx As WinForm.PictureBox = Forms("更改窗口").Controls("PictureBox1")
If Tables("person").Current Is Nothing Then
pbx.Image = Nothing
Else
pbx.Image = Tables("person").Current.DataRow.SQlLoadImage("photo") '从后台提取照片并显示
End If
End If
If Forms("查看窗口").Opened Then '如果窗口已经打开
Dim pbx As WinForm.PictureBox = Forms("查看窗口").Controls("PictureBox1")
If Tables("person").Current Is Nothing Then
pbx.Image = Nothing
Else
pbx.Image = Tables("person").Current.DataRow.SQlLoadImage("photo") '从后台提取照片并显示
End If
End If
在更改和查看窗口有如下代码:
Tables("person").RaiseCurrentChanged()
然后,在新增窗口增加人员无照片,打开更改和查看窗口前都会报错:参数无效
本来就没有下面这段代码
Dim cmd As SQLCommand = new SQLCommand()
cmd.ConnectionName = "SqlServerDB"
cmd.CommandText = "select 照片列 from 员工表 where 姓名 = '张三'"
Dim imageByte() As Byte = cmd.ExecuteScalar() '查询数据,并存入字节数组
Dim ms As New IO.MemoryStream(imageByte) '将字节数组转换为二进制流
Dim image As Image = Image.FromStream(ms) '将二进制流转换为图片
e.Form.Controls("PictureBox1").Image = image '显示图片
此主题相关图片如下:11.png
[此贴子已经被作者于2018/9/9 16:40:46编辑过]