vb 6.0将图像位图插入到ms access数据库 [英] vb 6.0 Insert image bitmap to ms access database

查看:228
本文介绍了vb 6.0将图像位图插入到ms access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的图片无法插入?这是我的代码。

  Sub SaveToDBs(strImagePath As String,fname As String)
rs.Close
rs.OpenSheet1,conn,adOpenDynamic,adLockBatchOptimistic,adCmdTable
Dim bytBLOB()As Byte
MsgBox strImagePath
Dim intNum As Integer
使用rs
intNum = FreeFile
打开strImagePath对于二进制作为#intNum
ReDim bytBLOB(FileLen(strImagePath))
'读取数据并关闭文件
获取#intNum,,bytBLOB
#1
.Fields(fname).AppendChunk bytBLOB
.Update
结束于
MsgBoxdone
End Sub



我有完成msgbox但图片未插入!!!!

方案

我通常使用ADODB.Stream这种东西 - 我发现比分块方法更容易理解。

 code> Sub SaveToDBs(strImagePath As String,fname As String)
rs.Close
rs.OpenSheet1,conn,adOpenDynamic,adLockBatchOptimistic,adCmdTable
MsgBox strImagePath
Dim intNum As Integer
Dim myStream as ADODB.Stream
使用rs
.AddNew
设置myStream = new ADODB.Stream
myStream.Type = adTypeBinary
myStream.LoadFromFile(strImagePath)
.Fields(fname)= myStream.Read
.Update
设置myStream =无
结束于
MsgBoxdone
End Sub

ADODB.Stream是从ADO 2.5版添加的:

ADO版本历史记录

ADO Stream文档


Why doesn't my image get inserted? Here is my code.

Sub SaveToDBs(strImagePath As String, fname As String)
rs.Close
rs.Open "Sheet1", conn, adOpenDynamic, adLockBatchOptimistic, adCmdTable
Dim bytBLOB() As Byte
MsgBox strImagePath
Dim intNum As Integer
With rs   
    intNum = FreeFile
    Open strImagePath For Binary As #intNum
    ReDim bytBLOB(FileLen(strImagePath))
    'Read data and close file
    Get #intNum, , bytBLOB
    Close #1
    .Fields(fname).AppendChunk bytBLOB
    .Update
End With
    MsgBox "done"
End Sub

I got "done" msgbox but image not inserted !!!!

解决方案

I normally use ADODB.Stream for this sort of thing - I find it easier to understand than the chunking methods.

Sub SaveToDBs(strImagePath As String, fname As String)
rs.Close
rs.Open "Sheet1", conn, adOpenDynamic, adLockBatchOptimistic, adCmdTable
MsgBox strImagePath
Dim intNum As Integer
Dim myStream as ADODB.Stream
With rs      
    .AddNew
    Set myStream = new ADODB.Stream
    myStream.Type = adTypeBinary
    myStream.LoadFromFile(strImagePath)
    .Fields(fname) = myStream.Read
    .Update
    Set myStream = Nothing
End With
    MsgBox "done"
End Sub

ADODB.Stream was added from ADO version 2.5:
ADO Version History
ADO Stream Documentation

这篇关于vb 6.0将图像位图插入到ms access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆