先临时记录下,以后再整理

将文件转换成二进制写入数据库:

Dim adodb1, adorec As Object
            Set adodb1 = OpenDatabase(App.Path & "\data.mdb")
            Set adorec = adodb1.OpenRecordset("select * from model")
            Dim stmpic As ADODB.Stream
            Dim strpictemp As String
            Set stmpic = New ADODB.Stream
            stmpic.Type = adTypeBinary
            adorec.MoveFirst
            Do While Not adorec.EOF
                    stmpic.Open
                    strpictemp = App.Path + "\" & Trim(adorec.Fields(1).Value)   '修改路径 By Daniel 2012-10-8
                    stmpic.LoadFromFile (strpictemp)
                    adorec.Edit
                    adorec.Fields(2).Value = stmpic.Read
                    adorec.Update
                    stmpic.Close
                    adorec.MoveNext
           Loop

 

还原代码:

Private Sub Command1_Click()
Set adoConnMDB = New ADODB.Connection
adoConnMDB.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};" & "Dbq=" & "d:\data.mdb;" & "Uid=;" & "Pwd=abc;"
adoConnMDB.Open
Dim adoRecDB As ADODB.Recordset
Set adoRecDB = New ADODB.Recordset
adoRecDB.Open "select * from model", adoConnMDB, 1, 3
adoRecDB.MoveFirst
Do While Not adoRecDB.EOF
code = adoRecDB(2).Value
FileName = adoRecDB(1).Value
Dim buffer() As Byte
ReDim buffer(adoRecDB(2).ActualSize)
buffer = code
Open "d:\" & FileName For Binary As #1
Put #1, , buffer
Close
adoRecDB.MoveNext
Loop
adoRecDB.Close
End Sub

 

  

posted on 2013-02-11 18:02  八风  阅读(658)  评论(0编辑  收藏  举报