为什么把本机word文件存到数据库后,再打开就成成乱码了.
代码如下:
=========================================================
Public Function FileSave(strFilePath As String)
Dim DocFilePath As String
Dim buf() As Byte
Dim intFileId As Long
Dim intFileSize As Long
Dim BLOCK_SIZE As Integer
Dim I As Integer, J As Integer, k As Integer
Dim rs As New ADODB.Recordset
Dim strSql As String
BLOCK_SIZE = 20000
intFileId = FreeFile()
Open strFilePath For Binary As #intFileId
intFileSize = LOF(intFileId) I = intFileSize \ BLOCK_SIZE
J = intFileSize Mod BLOCK_SIZE
ReDim buf(BLOCK_SIZE)
DoEvents strSql = "SELECT * FROM TB_任务文件 " _
& " WHERE ID=" & m.ID
rs.Open strSql, g.Cn, adOpenKeyset, adLockOptimistic
If rs.EOF Then
rs.AddNew
End If
For k = 1 To I
Get #intFileId, , buf()
rs("文件内容") = buf()
Next
If J <> 0 Then
ReDim buf(J)
Get #intFileId, , buf()
rs("文件内容").AppendChunk buf()
End If
rs.Update Close #intFileIdEnd Function
====================================
在线等!!!
代码如下:
=========================================================
Public Function FileSave(strFilePath As String)
Dim DocFilePath As String
Dim buf() As Byte
Dim intFileId As Long
Dim intFileSize As Long
Dim BLOCK_SIZE As Integer
Dim I As Integer, J As Integer, k As Integer
Dim rs As New ADODB.Recordset
Dim strSql As String
BLOCK_SIZE = 20000
intFileId = FreeFile()
Open strFilePath For Binary As #intFileId
intFileSize = LOF(intFileId) I = intFileSize \ BLOCK_SIZE
J = intFileSize Mod BLOCK_SIZE
ReDim buf(BLOCK_SIZE)
DoEvents strSql = "SELECT * FROM TB_任务文件 " _
& " WHERE ID=" & m.ID
rs.Open strSql, g.Cn, adOpenKeyset, adLockOptimistic
If rs.EOF Then
rs.AddNew
End If
For k = 1 To I
Get #intFileId, , buf()
rs("文件内容") = buf()
Next
If J <> 0 Then
ReDim buf(J)
Get #intFileId, , buf()
rs("文件内容").AppendChunk buf()
End If
rs.Update Close #intFileIdEnd Function
====================================
在线等!!!
代码:
================================================
Public Function ReadFile(lngID As Long, strFileName As String) As Integer
Dim FileArr() As Byte, current As String
Dim rs As New ADODB.Recordset
Dim strSql As String
Dim a As Integer
Dim Binarydata As Variant
Dim FileLen As Long
Dim totalsize As Variant
Dim bufferfile As Integer
On Error Resume Next
strSql = "SELECT * FROM TB_任务文件 " _
& " Where ID = " & lngID
rs.Open strSql, g.Cn, adOpenKeyset, adLockOptimistic totalsize = rs("文件内容").ActualSize
FileLen = rs.Fields("文件内容").ActualSize '得到office字段中的文件数据的大小
ReDim FileArr(FileLen + 1)
FileArr() = rs.Fields("文件内容").GetChunk(FileLen) '将字段中数据写入动态数组中
bufferfile = FreeFile
Open "c:\aa.doc" For Binary Access Read Write As
End If
Put bufferfile, , FileArr '将动态数组FileArr中的数据写入临时文件tempfile中 Close #bufferfile
End Function
================================================
Get #intFileId, , buf()
rs("文件内容") = buf()
Next写入数据库的时候就没写全文件呀,在循环的时候,把前面几次的数据都给替换掉了
Dim buf() As Byte
intFileId = FreeFile
Open strFilePath For Binary As #intFileId
ReDim buf(LOF(intFileId ) - 1)
Get #intFileId , , buf() rs("文件内容").AppendChunk buf()