我是新手 你说的我不明白,也不知道该写到哪里,可以帮忙做一下么,我实在糊涂的很,马上要交到老师那里了,拜托了。不胜感激
利用VB在SQL中存取图片
- 提问者网友:暗中人
- 2021-07-30 21:39
- 五星知识达人网友:忘川信使
- 2021-07-30 22:09
'读写二进制文件
Public Function FileSaveToField(ByRef rsField As Field, Optional TempFileName As String) As String
On Error GoTo funErr
If IsMissing(TempFileName) Or TempFileName = "" Then TempFileName = App.Path & "\temp"
'If tempFileName = "" Then tempFileName = App.Path & "\temp"
Dim i As Long
Dim Fragment As Integer, Fl As Long, Chunks As Integer
Dim Chunk() As Byte
Const ChunkSize As Long = 1024
Dim DataFile
DataFile = FreeFile
Open TempFileName For Binary Access Read As #DataFile
Fl = LOF(DataFile)
If Fl = 0 Then
Close DataFile
MsgBox "保存数据没有成功!"
Exit Function
End If
Chunks = Fl \ ChunkSize
Fragment = Fl Mod ChunkSize
ReDim Chunk(Fragment)
Get DataFile, , Chunk()
rsField.AppendChunk Chunk()
ReDim Chunk(ChunkSize)
For i = 1 To Chunks
Get DataFile, , Chunk()
DoEvents
rsField.AppendChunk Chunk()
DoEvents
RaiseEvent FileSaveToFieldProgress(i * ChunkSize, Fl)
Next
Close DataFile
FileSaveToField = TempFileName
Exit Function
funErr:
FileSaveToField = ""
End Function
Public Function FileReadFromField(ByRef rsField As Field, Optional TempFileName As String) As String
On Error GoTo funErr
If IsMissing(TempFileName) Or TempFileName = "" Then TempFileName = App.Path & "\temp"
Dim DataFile As Integer
Dim Fragment As Integer, Fl As Long, Chunks As Integer
Dim Chunk() As Byte
Dim lngOffset As Long, lngTotalSize As Long
Dim strChunk As String
Const ChunkSize As Integer = 1024
DataFile = FreeFile
Open TempFileName For Binary Access Write As #DataFile
lngTotalSize = rsField.ActualSize
Chunks = lngTotalSize \ ChunkSize
Fragment = lngTotalSize Mod ChunkSize
ReDim Chunk(ChunkSize)
Chunk() = rsField.GetChunk(ChunkSize)
Put #DataFile, , Chunk()
lngOffset = lngOffset + ChunkSize
Do While lngOffset < lngTotalSize
DoEvents
Chunk() = rsField.GetChunk(ChunkSize)
Put #DataFile, , Chunk()
lngOffset = lngOffset + ChunkSize
DoEvents
RaiseEvent FileReadFromFieldProgress(lngOffset, lngTotalSize)
Loop
DoEvents
Close #DataFile
FileReadFromField = TempFileName
Exit Function
funErr:
FileReadFromField = ""
ShowErr Err
On Error Resume Next
Close #DataFile
End Function
- 1楼网友:拾荒鲤
- 2021-07-30 22:17