以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  关于二进制列插入图片  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=107632)

--  作者:scofields
--  发布时间:2017/10/5 23:37:00
--  关于二进制列插入图片
老师,这段代码是大红袍老师给的,我怎么测试都实现不了在表中直接插入图片,好着急啊。帮忙改动一下
Dim c As new camera
Dim pic As WinForm.PictureBox = e.Form.Controls("PictureBox1")
Dim dr As DataRow = Tables("T_信息表").Current.DataRow
c.Capture() \'开始照相
If c.image IsNot Nothing Then \'照相成功
    pic.Image = c.Image
    Dim imgStream As New IO.MemoryStream
    Dim b As New Bitmap(pic.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.C
    cmd.CommandText = "Insert Into T_信息表 (ICON) values (0x" + ImageString + ")"  \'这里的ImageString 就是前4条几句根据图片转换来的字符串
    cmd.ExecuteNonQuery()
    End If

--  作者:有点甜
--  发布时间:2017/10/6 10:55:00
--  

 参考这里测试

 

http://www.foxtable.com/webhelp/scr/2950.htm

 

http://www.foxtable.com/webhelp/scr/2954.htm

 


--  作者:scofields
--  发布时间:2017/10/6 21:49:00
--  
反复测试,还是无法实现现拍的照片直接插入进去,反而是将图片插入到最后一行去了,也不知道是什么原因造成的。
--  作者:scofields
--  发布时间:2017/10/6 22:05:00
--  
晕死,我把照片先保存到本地,然后再去插入,这也一步到位,就这么简单的事,我都没有逆转过来,还在研究大红袍老师写的高深代码。话不多说,我直接提供拍照直插照片的代码。
Dim c As new camera
Dim pic As WinForm.PictureBox = e.Form.Controls("PictureBox1")
Dim dr As DataRow = Tables("T_信息表").Current.DataRow
c.Capture() \'开始照相
If c.image IsNot Nothing Then \'如果拍照成功
   c.Save("c:\\data\\abc.jpg") ‘然后将先保存到c盘data文件夹下,并把招盘取名为abc文件名
   dr.SQLInsertFile("ICON","c:\\data\\abc.jpg") \'再然后插入刚刚拍照的图像
   pic.Image = GetImage("c:\\data\\abc.jpg")
       End If
OK啦。
听蓝老师的话,先研究示例,示例隐藏着无限的智慧。


--  作者:有点甜
--  发布时间:2017/10/7 10:21:00
--  
以下是引用scofields在2017/10/6 21:49:00的发言:
反复测试,还是无法实现现拍的照片直接插入进去,反而是将图片插入到最后一行去了,也不知道是什么原因造成的。

 

1楼的代码 Insert Into 是插入一行新的行。如果你需要插入图片到一行已经存在的行,你应该写 update 表名 set ........

 

 

cmd.CommandText = "update T_信息表 set ICON = 0x" + ImageString + " where _Identify = " & dr("_Identify")