发信人: alex_d(枫之舞)
整理人: tidycc(2001-02-11 22:09:26), 站内信件
|
【 在 linkxl 的大作中提到:】
:怎样把数据库里的图片或声音字段还原为文件,哪有这方面的例子?
:......
可以用二进制流读出并写入文件。
这是我原来程序里的函数,用于access数据库用于存放图片字段的读出存为文件,希望有所帮助。
Function WriteOutObject(rsSource As Recordset, cField As String, cDest As String)
Dim iBlocks As Integer
Dim iDestHandle As Integer
Dim x As Integer
Dim ISourceLength As Long
Dim IRemaining As Long
' Dim cData As String
Dim cData() As Byte
Dim vntRetVal As Variant
ISourceLength = rsSource(cField).FieldSize()
If ISourceLength = 0 Then
WriteOutObject = 0
Exit Function
End If
iBlocks = ISourceLength \ BLOCK
IRemaining = ISourceLength Mod BLOCK
If Dir(cDest) <> "" Then
If MsgBox("Destination file already exists." + "Do you wish to overwrite?", vbYesNo) <> vbYes Then
WriteOutObject = 0
Exit Function
Else
Kill cDest
End If
End If
iDestHandle = 33
Open cDest For Binary As iDestHandle
Dim lngOffset As Long
ReDim cData(BLOCK)
' cData = rsSource(cField).GetChunk(0, IRemaining)
' Put iDestHandle, , cData
For x = 0 To iBlocks
cData() = rsSource(cField).GetChunk(lngOffset, BLOCK)
Put iDestHandle, , cData()
lngOffset = lngOffset + BLOCK
Next x
' For x = 1 To iBlocks
' cData = rsSource(cField).GetChunk((x - 1) * BLOCK + IRemaining, BLOCK)
' Put iDestHandle, , cData
' Next x
Close iDestHandle
WriteOutObject = ISourceLength
End Function |
|