用SQL语句录入的话应该是FIELD(1)。APPENDCHUNK
解决方案 »
- 高手请看一下将文本写入excel错在何处
- 重开一贴讨论VB过时的问题
- 大家看我的问题错那了,知道 的说声,谢谢分全给你!
- 300元RMB求解决一个SendMessage的问题
- VB 的DTPicker下拉选择时能用鼠标选 yyyy-MM-dd hh:mm:ss中的hh:mm:ss部分吗?
- 一个有关组合框的问题
- 如何等待一个程序运行结束?下面的代码怎么不对?在线等待,解决立刻结贴!
- 一張有音樂的圖片的問題??
- VB中用什么命令保存文件呀???
- 江东程序员大聚会(不是江苏的别进来!)
- variant变量能够存储用户定义类型(结构体)变量吗?急。。。
- 求软件:crystal report 8.5 愿意用软件或技术交换(无内容)
存文件到数据库Public Function AddFile() As Boolean 'Return boolean to decide whether refresh files list Dim strBin As String * 3000 Dim btyGet() As Byte Dim lngBlockIndex As Long Dim lngBlocks As Long Dim lngLastBlock As Long Dim lngPosition As Long Dim lngFileLenth As Long Dim lngIndex As Long With frmBinary.CommonDialog1 '.InitDir = App.Path .Filter = "All image files|*.bmp;*.ico;*.jpg;*.gif|Bitmap files|*.bmp|Icon files|*.ico|All files|*.*" .FileName = "" On Error GoTo ErrorHandle .ShowOpen On Error GoTo 0 If .FileName <> "" Then Open .FileName For Binary As #1 lngFileLenth = LOF(1) lngPosition = 0 'Get block count for loop lngBlocks = lngFileLenth \ BlockSize 'Get lngth of last block for the last read lngLastBlock = lngFileLenth Mod BlockSize rsBinary.AddNew rsBinary.Fields("typecode") = TypeCode For lngBlockIndex = 1 To lngBlocks ReDim btyGet(BlockSize) Get #1, , btyGet() rsBinary.Fields("content").AppendChunk btyGet() lngPosition = lngPosition + BlockSize Next If lngLastBlock > 0 Then ReDim btyGet(lngLastBlock) Get #1, , btyGet() rsBinary.Fields("content").AppendChunk btyGet() End If rsBinary.Update Close #1 AddFile = True MsgBox "Save finished", vbInformation Else AddFile = False End If End With Exit FunctionErrorHandle: AddFile = FalseEnd Function从数据库取文件出来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 Exit SubErrorHandle: End Sub
Private Sub SaveToDB(ByRef fld As ADODB.Field, DiskFile As String)
Dim bytedata() As Byte
Dim NumBlocks As Long
Dim FileLength As Long
Dim LeftOver As Long
Dim SourceFile As Long
Dim i As Long
Const BLOCKSIZE = 4096 SourceFile = FreeFile
Open DiskFile For Binary Access Read As SourceFile
FileLength = LOF(SourceFile)
If FileLength = 0 Then
Close SourceFile
MsgBox DiskFile & "错误的图片内容!"
Else
NumBlocks = FileLength \ BLOCKSIZE
LeftOver = FileLength Mod BLOCKSIZE
fld.Value = Null
ReDim bytedata(BLOCKSIZE)
For i = 1 To NumBlocks
Get SourceFile, , bytedata()
fld.AppendChunk bytedata()
Next i
ReDim bytedata(LeftOver)
Get SourceFile, , bytedata()
fld.AppendChunk bytedata()
Close SourceFile
End If
End Sub ‖天天写程序‖
‖夜夜泡小妞‖
‖身兼数职做代码‖
‖晚晚工作到天明‖
‖为何人生如此苦‖
‖泡妞消费数目高‖
‖我看世俗本无趣‖
‖程序伤神妞伤人‖
‖不再见女人‖
‖不想写程序‖