以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  SQLInsertFile问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=110482)

--  作者:goldenfont
--  发布时间:2017/12/4 14:26:00
--  SQLInsertFile问题
编辑一个数据行,有一列是二进制列,新增或者修改的时候,此字段用SQLInsertFile的办法会跳出“未将对象引用到对象的实例”错误

Dim dr As DataRow = Tables("商品信息").Current.DataRow
dr.Save
\'保存图片
Dim pic1 As WinForm.PictureBox = e.Form.Controls("PictureBox1")
dr.SQLInsertFile("示意图1",pic1.ImageFile)


--  作者:有点甜
--  发布时间:2017/12/4 15:00:00
--  

必须先保存,才能用sqlinsertfile插入的,如

 

pic1.image.save(projectpath & "temp.jpg")

dr.SQLInsertFile("示意图1", projectpath & "temp.jpg")

 


--  作者:goldenfont
--  发布时间:2017/12/4 15:54:00
--  
搞定了,谢谢
--  作者:goldenfont
--  发布时间:2017/12/4 17:36:00
--  
老师,出了个新问题,保存好以后,总是会出现“所选的图片被另一个进程占用。。。。。。”的错误提示,但是把错误框点掉后也是能正常显示和使用的,这是啥意思?难道是每次保存成一个固定的临时图片文件引起的?
--  作者:有点甜
--  发布时间:2017/12/4 17:56:00
--  

这样写代码吧

 


Dim imgStream As New IO.MemoryStream
Dim b As New Bitmap(pic1.Image)
b.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim imageByte As Byte() = imgStream.GetBuffer
imgStream.Dispose()
Dim ImageString As String = BitConverter.ToString(imageByte).Replace("-", "")  \' SQLCommand 不能直接Insert 二进制,只能拼接SQL语句,所以这里把二进制变成字符
Dim cmd As SQLCommand = new SQLCommand()
cmd.ConnectionName = "数据源名"
cmd.CommandText = "update " & dr.datatable.name & " set 示意图1 = 0x" + ImageString + " where _Identify = " & dr("_Identify")
cmd.ExecuteNonQuery()