数据库字段:wjmc 文件名,wjsx 文件的扩展名。Wjnr 文件的内容为二进制。(若access数据库为“ole对象”,sql server为“image”)
该程序可以操作所有的文件类型。
Dim Wenjian As String
Dim RD As Byte
Dim SIZE As Long
Const MYSIZE = 1048576
Dim WENJIANN() As Byte
Dim Rs As New ADODB.Recordset
Rs.Open "select * from wj", Cn, 1, 3
Rs.AddNew
Rs!wjmc = Mid(Name, 1, InStr(Name, ".") - 1)
Rs!wjsx = Mid(Name, InStr(Name, ".") + 1)
‘name为文件的名称加扩展名
Open Filename For Binary Access Read As #1
SIZE = LOF(1)
Do While SIZE - MYSIZE >= 0
ReDim WENJIANN(MYSIZE) As Byte
Get #1, , WENJIANN
Rs!wjnr.AppendChunk WENJIANN
SIZE = SIZE - MYSIZE
Loop
If SIZE > 0 Then
ReDim WENJIANN(SIZE) As Byte
Get #1, , WENJIANN
Rs!wjnr.AppendChunk WENJIANN
End If
Close #1
Rs.Update
Set Rs = Nothing
