我想数据库存储文件,我使用了ado类,我按例子做了一下,存是没有问题了,但取出来的时间出错,请原因。错误的语句 :Chunk() = dbRecordset2("内容" & Num).GetChunk(Fragment)
错误描述: 3421 应用程序目前操作所使用的值的类型不正确。我的原代码:
Private Sub ExportFile(Num As Integer)
Dim strFilePath As String
Dim I As Integer
Dim intChunks As Integer, lngFileLen As Long
Dim Fragment As Integer, Chunk() As Byte
Const ChunkSize As Integer = 16384On Error GoTo ErrorHandler
If Len(Controls("texFilePath" & Num).Text) > 0 Then
CommonDialog1.CancelError = True
CommonDialog1.FileName = Controls("texFilePath" & Num).Text
CommonDialog1.Filter = "所用文件(*.*)|*.*"
CommonDialog1.ShowOpen
strFilePath = CommonDialog1.FileName
If dbRecordset2.State = 2 Then
dbRecordset2.Close
End If
dbRecordset2.Source = "select 内容" & Num & " from 文档中心内容表 where 编号=" & dbRecordset!编号
dbRecordset2.Open
lngFileLen = dbRecordset2("内容" & Num).ActualSize
Fragment = lngFileLen Mod ChunkSize
intChunks = lngFileLen \ ChunkSize
ReDim Chunk(Fragment)
Open strFilePath For Binary Access Write As #1
Chunk() = dbRecordset2("内容" & Num).GetChunk(Fragment)
Put #1, , Chunk
ReDim Chunk(ChunkSize)
For I = 1 To intChunks
Chunk() = dbRecordset2("内容" & Num).GetChunk(ChunkSize)
Put #1, , Chunk
Next
Close #1
vbmsg = MsgBox("成功导出文件", vbOKOnly, "操作结果")
Else
vbmsg = MsgBox("没有可导出的文件", vbOKOnly, "提示")
End If
Exit Sub
ErrorHandler:
End Sub
错误描述: 3421 应用程序目前操作所使用的值的类型不正确。我的原代码:
Private Sub ExportFile(Num As Integer)
Dim strFilePath As String
Dim I As Integer
Dim intChunks As Integer, lngFileLen As Long
Dim Fragment As Integer, Chunk() As Byte
Const ChunkSize As Integer = 16384On Error GoTo ErrorHandler
If Len(Controls("texFilePath" & Num).Text) > 0 Then
CommonDialog1.CancelError = True
CommonDialog1.FileName = Controls("texFilePath" & Num).Text
CommonDialog1.Filter = "所用文件(*.*)|*.*"
CommonDialog1.ShowOpen
strFilePath = CommonDialog1.FileName
If dbRecordset2.State = 2 Then
dbRecordset2.Close
End If
dbRecordset2.Source = "select 内容" & Num & " from 文档中心内容表 where 编号=" & dbRecordset!编号
dbRecordset2.Open
lngFileLen = dbRecordset2("内容" & Num).ActualSize
Fragment = lngFileLen Mod ChunkSize
intChunks = lngFileLen \ ChunkSize
ReDim Chunk(Fragment)
Open strFilePath For Binary Access Write As #1
Chunk() = dbRecordset2("内容" & Num).GetChunk(Fragment)
Put #1, , Chunk
ReDim Chunk(ChunkSize)
For I = 1 To intChunks
Chunk() = dbRecordset2("内容" & Num).GetChunk(ChunkSize)
Put #1, , Chunk
Next
Close #1
vbmsg = MsgBox("成功导出文件", vbOKOnly, "操作结果")
Else
vbmsg = MsgBox("没有可导出的文件", vbOKOnly, "提示")
End If
Exit Sub
ErrorHandler:
End Sub
返回大型文本或二进制数据 Field 对象的全部或部分内容 。语法variable = field.GetChunk( Size )返回值返回变体型。
lngFileLen = dbRecordset2("内容" & Num).ActualSize
可以正确获取长度
Dim a(2) As String
a(1) = "a"
a(2) = "b"
Dim b(2) As String
'b = a 数组是不可以这样复制拷贝的
Dim i As Integer
For i = 1 To UBound(a)
b(i) = a(i)
Next
MsgBox b(1)
End Sub
但 msdn的例子的确这是写的。