gpt4 book ai didi

database - vb 6.0 插入图片位图到ms access数据库

转载 作者:搜寻专家 更新时间:2023-10-30 22:03:45 25 4
gpt4 key购买 nike

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

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

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

最佳答案

我通常使用 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 Version History
ADO Stream Documentation

关于database - vb 6.0 插入图片位图到ms access数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5641835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com