模块:
Dim LngOffset As Long, Chunks As Integer, LngTotaSize As Long
Dim Fragment As Integer, Chunk() As Byte, i As Long
Const ChunkSize As Integer = 2384
Dim Mediatemp As String
Public Function ShowPicture(ByVal DataFile As String, ByVal SQL As String, ByVal SQLZD As String) '显示图片
Dim Rs As New ADODB.Recordset
Rs.Open SQL, DataConn, adOpenKeyset, adLockOptimistic
Rs.MoveLast
Open DataFile For Binary As 1
Chunk = Rs.Fields(SQLZD) '将二进制数据读出写入文件。
Put 1, , Chunk
Close 1
Rs.Close
End Function
Public Function SavePicture4(ByVal DataFile As String, ByVal SQL As String, ByVal SQLZD As String) As Integer '保存图片
Dim Rs As New ADODB.Recordset
If DataFile = "" Then
Exit Function: SavePicture4 = 0
End If
Open DataFile For Binary As 1
Rs.Open SQL, DataConn, adOpenKeyset, adLockOptimistic
If FileLen(DataFile) = True Then Close 1: Exit Function: SavePicture4 = 0 '文件大小为零的处理
Chunks = FileLen(DataFile) / ChunkSize
Fragment = FileLen(DataFile) Mod ChunkSize
ReDim Chunk(Fragment) '根据文件长度定义动态数组大小
Get 1, , Chunk() '将一个已打开的磁盘文件读入数组变量之中
Rs.Update
Rs.Fields(SQLZD).AppendChunk Chunk()
'将得到的值写入数据库
ReDim Chunk(ChunkSize)
For i = 1 To Chunks
Get 1, , Chunk()
Rs.Fields(SQLZD).AppendChunk Chunk()
'将得到的值写入数据库
Next i
Close 1
Rs.Update
Rs.Close
SavePicture4 = 1
End Function
使用方法:
保存:
SQL = "SELECT * FROM T_Stuent_Info WHERE Code='" & Trim(Text1(0).Text) & "'"
a = SavePicture4(Text3.Text, SQL, "Photo") '保存图片
显示:
SQL = "SELECT Photo FROM T_Stuent_Info WHERE Code='" & Trim(Text1(0).Text) & "'"
Text3.Text = "C:/Temp.jpg"
Call ShowPicture("C:/Temp.jpg", SQL, "Photo")
然后调用生成的这个临时图片就可以了.