如何才能往数据库里读取图片数据或者从数据库里读图片

如何才能往数据库里读取图片数据或者从数据库里读图片,第1张

给你提供个ACCESS版的VB代码,使用时调用这些过程即可:
'使用ADODBStream来保存/读取图像文件到数据
'引用Microsoft ActiveX Data Objects 25 Library及以上版本

'保存文件到数据库中
Sub SaveFile()
Dim Stm As New ADODBStream
Dim Cnn As New ADODBConnection
Dim rs As New ADODBRecordset
Dim strCnn As String

strCnn = "Provider=MicrosoftJetOLEDB40;Persist Security Info=False;Data Source=" & _
AppPath & "\DB1mdb"
CnnOpen strCnn

'读取文件到内存(二进制模式)
With Stm
Type = adTypeBinary
Open
LoadFromFile AppPath + "\Image1bmp"
End With

With rs
Open "SELECT FROM TABLE1", Cnn, 1, 3
AddNew
Fields("IMAGE") = StmRead
Update
End With

rsClose
StmClose
Set rs = Nothing
Set Cnn = Nothing
Set Stm = Nothing
End Sub
'从数据库中读取图像文件
Sub ReadFile()
Dim Stm As New ADODBStream
Dim Cnn As New ADODBConnection
Dim rs As New ADODBRecordset
Dim strCnn As String

strCnn = "Provider=MicrosoftJetOLEDB40;Persist Security Info=False;Data Source=" & _
AppPath & "\DB1mdb"
CnnOpen strCnn
rsOpen "SELECT IMAGE FROM TABLE1 WHERE ID = 18", Cnn, adOpenKeyset, adLockReadOnly

'保存到文件
With Stm
Mode = adModeReadWrite
Type = adTypeBinary
Open
Write rs("IMAGE")
SaveToFile AppPath + "\Image2bmp"
End With

'显示
Picture1Picture = LoadPicture(AppPath + "\Image2bmp")

rsClose
StmClose
Set rs = Nothing
Set Cnn = Nothing
Set Stm = Nothing
End Sub

以上就是关于如何才能往数据库里读取图片数据或者从数据库里读图片全部的内容,包括:如何才能往数据库里读取图片数据或者从数据库里读图片、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9707358.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存