vb 6.0 插入图像位图到ms access数据库

发布于 2024-11-01 01:50:50 字数 558 浏览 0 评论 0原文

为什么我的图像没有插入?这是我的代码。

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

我得到了“完成”消息框,但图像未插入!!!!

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 !!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-11-08 01:50:50

我通常使用 ADODB.Stream 来做这类事情 - 我发现它比分块方法更容易理解。

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 是从 ADO 版本 2.5 添加的:
ADO 版本历史记录
ADO 流文档

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

望她远 2024-11-08 01:50:50

您必须将位图保留在结构化存储中,MS Access 绑定才能按预期工作。

看看 Edanmo 的 加载图片并将其保存到字节数组以兼容方式序列化的示例。然后,如果记录集字段是客户端字段,则可以使用简单分配来更新记录集字段。

You have to persist bitmaps in structured storage for the MS Access binding to work as expected.

Take a look at Edanmo's Load and save pictures to byte arrays. sample for a way to serialize in a compatible way. Then you could use simple assignment to update your recordset field if it's a client side one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文