'储存
Private Sub SavePic()
Dim Conn As New ADODB.Connection
Dim Rs0 As New ADODB.Recordset
Dim Rs As New ADODB.Recordset
Dim Maxnumber As Long
Dim Sql As String
Dim Connstr As String
Dim picarray() As Byte
Dim piclenth As Long
Rs.Open "save", Conn, , , adCmdTable
Rs.AddNew
Rs("title") = Trim(Text3.Text)
If Trim(Text1.Text) = "在此处输入备注信息" Then
Rs("note") = ""
Else
Rs("note") = Trim(Text1.Text)
End If
piclenth = FileLen(App.Path & "\mydoc.doc")
ReDim picarray(piclenth)
Open App.Path & "\mydoc.doc" For Binary Access Read As #1
Get #1, , picarray()
Close #1
Rs("pic").AppendChunk picarray
Rs.Update
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
End Sub
'读出
Private Sub ReadPic()
Dim Conn As New ADODB.Connection
Dim Rs0 As New ADODB.Recordset
Dim Rs As New ADODB.Recordset
Dim Maxnumber As Long
Dim Sql As String
Dim Connstr As String
Dim picarray() As Byte
Dim piclenth As Long
Open App.Path & "\doc1.doc" For Binary Access Write As #1
Put #1, , picarray()
Close #1
Picture1.Picture = LoadPicture(App.Path & "\doc1.doc")
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
End Sub
从数据库取文件出来
Public Sub SaveFile(ByVal FileID As Long)
Dim lngBlockCount As Long
Dim lngLastBlock As Long
Dim lngI As Long
Dim btyBlock() As Byte
Dim lngResult As Long
If rsBinary.EOF And rsBinary.BOF Then Exit Sub
rsBinary.MoveFirst
rsBinary.Find " id=" & FileID
If Not rsBinary.EOF Then
With frmBinary.CommonDialog1
.FileName ="TempSave"
'.InitDir = App.Path
'If user cancel save the goto handle
On Error GoTo ErrorHandle
.ShowSave
If .FileName <> "" Then
lngBlockCount = rsBinary.Fields("content").ActualSize \ BlockSize
lngLastBlock = rsBinary.Fields("content").ActualSize Mod BlockSize
If Dir(.FileName) <> "" Then
If MsgBox("File " & .FileName & " is exist,overwrite?", vbYesNo + vbQuestion) = vbYes Then
Kill .FileName
Else
Exit Sub
End If
Else
End If
Open .FileName For Binary As #1
ReDim btyBinary(BlockSize)
For lngI = 1 To lngBlockCount
btyBlock() = rsBinary.Fields("content").GetChunk(BlockSize)
Put #1, , btyBlock
Next
If lngLastBlock <> 0 Then
ReDim btyBlock(lngLastBlock)
btyBlock() = rsBinary.Fields("content").GetChunk(lngLastBlock)
Put #1, , btyBlock
End If
Close #1
MsgBox .FileName & " is saved", vbInformation
Else
End If
End With
End If