qq_36805380 2016-12-07 12:21 采纳率: 72.7%
浏览 962
已结题

vb.net向access插入图片问题

图片说明代码运行能够插入图片,但是插入的时候是直接插到空的字段(第9、10行)了,求教!
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If PictureBox1.Image Is Nothing Then
MsgBox("请先选择图片", MsgBoxStyle.Exclamation)
Exit Sub
End If
Dim fs As FileStream = New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim bt(fs.Length) As Byte
fs.Read(bt, 0, fs.Length)
fs.Close()
fs = Nothing
Dim oleCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand
DBInit()
oleCmd.Connection = Cnn
oleCmd.CommandType = CommandType.Text
oleCmd.CommandText = "INSERT INTO TestImg (img) VALUES (@img)"
oleCmd.Parameters.Add("@img", OleDb.OleDbType.Binary).Value = bt
oleCmd.ExecuteNonQuery()
oleCmd = Nothing
DBRelease()
MsgBox("图片插入成功")
End Sub

Private Sub DBInit() '定义
Try
Cnn = New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & Application.StartupPath & "\Test.mdb;User Id=Admin;Jet OLEDB:Database Password=;")
cnn.Open()
Catch exp As OleDb.OleDbException
MsgBox(exp.Message)
End
End Try
End Sub
Private Sub DBRelease()
cnn.Close()
cnn = Nothing
End Sub

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-12-07 15:51
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作