Foxtable(狐表)用户栏目专家坐堂 → 关于二进制列插入图片


  共有1486人关注过本帖平板打印复制链接

主题:关于二进制列插入图片

帅哥哟,离线,有人找我吗?
scofields
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:561 积分:4516 威望:0 精华:0 注册:2016/4/17 20:05:00
关于二进制列插入图片  发帖心情 Post By: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

 回到顶部