这是一个写数据库和读数据库的代码,直接粘贴到你的代码中即可!!! Public Sub WriteDB(Col As ADODB.Field, ImgFile As String, Optional BlockSize As Long = 8192) Dim byteData() As Byte, FileLength As Long, NumBlocks As Integer Dim LeftOver As Long, SourceFileNum As Integer, i As Integer SourceFileNum = FreeFile'打开的文件号 你可以直接写 例如: 1 Open ImgFile For Binary As #SourceFileNum'ImgFile是图片所在目录 FileLength = LOF(SourceFileNum) If FileLength > 50 Then NumBlocks = FileLength / BlockSize LeftOver = FileLength Mod BlockSize ReDim byteData(LeftOver) Get #SourceFileNum, , byteData() Col.AppendChunk byteData() ReDim byteData(BlockSize) For i = 1 To NumBlocks Get #SourceFileNum, , byteData() Col.AppendChunk byteData() Next End If Close #SourceFileNum End Sub '读数据库Public Function ReadDB(Col As ADODB.Field, ImgFile As String, Optional BlockSize As Long = 8192) As Boolean Dim byteData() As Byte, NumBlocks As Integer Dim LeftOver As Long, DestFileNum As Integer, i As Integer Dim ColSize As LongOn Error GoTo ErrRead ReadDB = False If Dir(ImgFile) = "tmpImage" Then Kill ImgFile DestFileNum = FreeFile'同样是文件号 可以是 1 Open ImgFile For Binary As #DestFileNum'ImgFile读数据库后得到的图片文件名 ColSize = Col.ActualSize NumBlocks = ColSize / BlockSize LeftOver = ColSize Mod BlockSize ReDim byteData(LeftOver) byteData() = Col.GetChunk(LeftOver) Put #DestFileNum, , byteData() ReDim byteData(BlockSize) For i = 1 To NumBlocks byteData() = Col.GetChunk(BlockSize) Put #DestFileNum, , byteData() Next If LOF(DestFileNum) > 200 Then ReadDB = True Close #DestFileNum Exit FunctionErrRead: MsgBox "读“图形”信息文件失败," & err.Number, vbOKOnly + vbInformation ReadDB = False Exit Function End Function '//如果ReadDB=False则写文件失败。 '这里是我的源代码,你Copy后直接使用即可!!!'祝 你成功!!!
Public Sub WriteDB(Col As ADODB.Field, ImgFile As String, Optional BlockSize As Long = 8192)
Dim byteData() As Byte, FileLength As Long, NumBlocks As Integer
Dim LeftOver As Long, SourceFileNum As Integer, i As Integer SourceFileNum = FreeFile'打开的文件号 你可以直接写 例如: 1
Open ImgFile For Binary As #SourceFileNum'ImgFile是图片所在目录
FileLength = LOF(SourceFileNum)
If FileLength > 50 Then
NumBlocks = FileLength / BlockSize
LeftOver = FileLength Mod BlockSize
ReDim byteData(LeftOver)
Get #SourceFileNum, , byteData()
Col.AppendChunk byteData()
ReDim byteData(BlockSize)
For i = 1 To NumBlocks
Get #SourceFileNum, , byteData()
Col.AppendChunk byteData()
Next
End If
Close #SourceFileNum
End Sub
'读数据库Public Function ReadDB(Col As ADODB.Field, ImgFile As String, Optional BlockSize As Long = 8192) As Boolean
Dim byteData() As Byte, NumBlocks As Integer
Dim LeftOver As Long, DestFileNum As Integer, i As Integer
Dim ColSize As LongOn Error GoTo ErrRead
ReadDB = False If Dir(ImgFile) = "tmpImage" Then Kill ImgFile DestFileNum = FreeFile'同样是文件号 可以是 1
Open ImgFile For Binary As #DestFileNum'ImgFile读数据库后得到的图片文件名 ColSize = Col.ActualSize
NumBlocks = ColSize / BlockSize
LeftOver = ColSize Mod BlockSize ReDim byteData(LeftOver)
byteData() = Col.GetChunk(LeftOver)
Put #DestFileNum, , byteData()
ReDim byteData(BlockSize)
For i = 1 To NumBlocks
byteData() = Col.GetChunk(BlockSize)
Put #DestFileNum, , byteData()
Next
If LOF(DestFileNum) > 200 Then ReadDB = True
Close #DestFileNum
Exit FunctionErrRead:
MsgBox "读“图形”信息文件失败," & err.Number, vbOKOnly + vbInformation
ReadDB = False
Exit Function
End Function '//如果ReadDB=False则写文件失败。
'这里是我的源代码,你Copy后直接使用即可!!!'祝 你成功!!!