以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- PositionChanged事件里这样写代码有问题吗? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=147737) |
-- 作者:goldenfont -- 发布时间:2020/3/23 10:25:00 -- PositionChanged事件里这样写代码有问题吗? 数据库中字段存放的是base64字符,然后切换记录时显示对应的图片 \'+++++++根据当前记录显示数据库中的图片++++++++++++++++ If e.Table.Cols.Contains("产品编号") Then Dim cmd As New SQLCommand cmd.C cmd.CommandText = "s elect 示意图 from ZL_SKU where SKU编码=\'" & cur("产品编号") & "\'" If cmd.ExecuteScalar <> "" Then e.Form.Controls("PictureBox1").Image = Functions.Execute("Base64ToImage",cmd.ExecuteScalar) Else e.Form.Controls("PictureBox1").Image = Nothing End If End If 第一次加载时会出现“未将对象引用设置到对象的实例。”关掉就好了,这是什么问题?
|
-- 作者:有点蓝 -- 发布时间:2020/3/23 11:23:00 -- 二进制图片? Dim cmd As new SQLCommand cmd.ConnectionName = "xxx" cmd.CommandText="s elect 示意图 from ZL_SKU where SKU编码=\'" & cur("产品编号") & "\'" Dim dt As DataTable = cmd.ExecuteReader Dim src As String If dt.DataRows.Count >0 Then Dim imagebytes As Byte() = dt.DataRows(0)("示意图") Dim stream As System.IO.Stream = New System.IO.MemoryStream(imagebytes) Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(stream) e.Form.Controls("PictureBox1").Image = bmp End If |
-- 作者:goldenfont -- 发布时间:2020/3/23 12:11:00 -- 不是二进制图片,是base64的字符串 Dim bs As Byte() = Convert.FromBase64String(base64) Dim stream As System.IO.Stream = New System.IO.MemoryStream(bs) Return Image.FromStream(stream,False) |
-- 作者:有点蓝 -- 发布时间:2020/3/23 14:21:00 -- If e.Table.Cols.Contains("产品编号") Then Dim cmd As New SQLCommand cmd.C cmd.CommandText = "s elect 示意图 from ZL_SKU where SKU编码=\'" & cur("产品编号") & "\'" dim str as string = cmd.ExecuteScalar If str > "" Then e.Form.Controls("PictureBox1").Image = Functions.Execute("Base64ToImage",str) Else e.Form.Controls("PictureBox1").Image = Nothing End If End If
|