vb 6.0 插入图像位图到ms access数据库
为什么我的图像没有插入?这是我的代码。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常使用 ADODB.Stream 来做这类事情 - 我发现它比分块方法更容易理解。
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.
ADODB.Stream was added from ADO version 2.5:
ADO Version History
ADO Stream Documentation
您必须将位图保留在结构化存储中,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.