|
楼主 |
发表于 2016-3-18 18:01
|
显示全部楼层
本帖最后由 这货是菜鸟 于 2016-3-18 18:24 编辑
Sub t2() '向数据库添加图片
Dim cnn, rst, stm
Set cnn = CreateObject("adodb.connection")
Set rst = CreateObject("adodb.recordset")
Set stm = CreateObject("adodb.stream")
cnn.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & ThisWorkbook.Path & "/data.mdb;Jet OLEDB:Database Password=" & "123456"
rst.Open "select * from 商品图", cnn, 1, 3 '1,1为只读数据,1,3为插入数据,2,3是修改数据
With stm
.Mode = 3 '1:binary(二进制流) 2:text(文本)
.Type = 1 '1:Read 2:Write 3:ReadWrite
.Open
End With
rst.AddNew
rst.Fields(0) = "a6"
stm.LoadFromFile ThisWorkbook.Path & "\c.jpg"
rst.Fields(1).Value = stm.Read
rst.Update
rst.Close
stm.Close
cnn.Close
Set rst = Nothing
Set stm = Nothing
Set cnn = Nothing
End Sub
Sub t3() 'excel读取数据库的图片
Dim cnn, rst, stm
Set cnn = CreateObject("adodb.connection")
Set rst = CreateObject("adodb.recordset")
Set stm = CreateObject("adodb.stream")
cnn.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & ThisWorkbook.Path & "/data.mdb;Jet OLEDB:Database Password=" & "123456"
rst.Open "select * from 商品图 where 商品编码='a6'", cnn, 1, 3 '1,1为只读数据,1,3为插入数据,2,3是修改数据
With stm
.Type = 1 '1:binary(二进制流) 2:text(文本)
.Mode = 3 '1:Read 2:Write 3:ReadWrite
.Open
End With
stm.write (rst.Fields(1).Value)
stm.savetofile ThisWorkbook.Path & "\0.jpg", adSaveCreateOverWrite
ActiveSheet.Pictures.Insert(ThisWorkbook.Path & "\0.jpg").Select
rst.Close
stm.Close
cnn.Close
Set rst = Nothing
Set stm = Nothing
Set cnn = Nothing
End Sub
|
|