把图片保存到数据库
Dim Chunk() As Byte
Const ChunkSize As Integer = 2384
Dim DataFile As Integer, Chunks, Fragment As Integer
Dim MediaTemp As String
Dim lngOffset, lngTotalSize As Long
Dim filelen As Long
DataFile = 1
Open Path_Picture For Binary Access Read As DataFile
filelen = LOF(DataFile) ' 文件中数据长度
Chunks = filelen \ ChunkSize
Fragment = filelen Mod ChunkSize
ReDim Chunk(Fragment)
Get DataFile, , Chunk()
mrc.Fields(2).AppendChunk Chunk() 'mrc as ADODB.RECORDSET,Fields(2)是数据库里保存图片的字段
ReDim Chunk(ChunkSize)
For i = 1 To Chunks
Get DataFile, , Chunk()
mrc.Fields(2).AppendChunk Chunk()
Next
Close DataFile
读取图片
'从字段里把二进制数据提取出来保存到数组中
Chunks = lngTotalSize \ ChunkSize
Fragment = lngTotalSize Mod ChunkSize
ReDim Chunk(Fragment)
Chunk() = mrc.Fields(2).GetChunk(Fragment)
Open "c:\UserPicture.JPG" For Binary As #1 '建立临时文件
Put #1, , Chunk() '把读取的二进制数组输出到临时文件里
For i = 1 To Chunks
ReDim Chunk(ChunkSize)
Chunk() = mrc.Fields(2).GetChunk(ChunkSize)
Put #1, , Chunk()
Next
Close #1
imgUserPicture.Picture = LoadPicture("c:\UserPicture.JPG") '从临时文件加载图片
Kill ("c:\userpicture.JPG") '删除临时文件
Erase Chunk()
楼主参考一下吧,可能对你有点启发