这是代码Sub tEmp1()
Dim strFree As String
Dim lngFileLen As Long
Dim bytFile() As Byte
Dim lngBlocks As Long
Dim lngLeft As Long
Dim lngNum As Long If imgFileName <> "" Then
strFree = FreeFile
Open imgFileName For Binary Access Read As strFree
lngFileLen = LOF(strFree)
If lngFileLen > 0 Then
lngBlocks = lngFileLen / BLOCK_SIZE
lngLeft = lngFileLen Mod BLOCK_SIZE
ReDim bytFile(BLOCK_SIZE)
For lngNum = 1 To lngBlocks
Get strFree, , bytFile()
rs("图片").AppendChunk bytFile() ---->运行到这就出错
Next lngNum
If lngLeft > 0 Then
ReDim bytFile(lngLeft)
Get strFree, , bytFile()
rs("图片").AppendChunk bytFile()
End If
End If
End If End Sub
Dim strFree As String
Dim lngFileLen As Long
Dim bytFile() As Byte
Dim lngBlocks As Long
Dim lngLeft As Long
Dim lngNum As Long If imgFileName <> "" Then
strFree = FreeFile
Open imgFileName For Binary Access Read As strFree
lngFileLen = LOF(strFree)
If lngFileLen > 0 Then
lngBlocks = lngFileLen / BLOCK_SIZE
lngLeft = lngFileLen Mod BLOCK_SIZE
ReDim bytFile(BLOCK_SIZE)
For lngNum = 1 To lngBlocks
Get strFree, , bytFile()
rs("图片").AppendChunk bytFile() ---->运行到这就出错
Next lngNum
If lngLeft > 0 Then
ReDim bytFile(lngLeft)
Get strFree, , bytFile()
rs("图片").AppendChunk bytFile()
End If
End If
End If End Sub
改为
Open imgFileName For Binary Access Write As strFree
能够对文件输入/输出 (I/O)。语法Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength]Open 语句的语法具有以下几个部分:部分 描述
pathname 必要。字符串表达式,指定文件名,该文件名可能还包括目录、文件夹及驱动器。
mode 必要。关键字,指定文件方式,有 Append、Binary、Input、Output、或 Random 方式。如果未指定方式,则以 Random 访问方式打开文件。
**********
access 可选。关键字,说明打开的文件可以进行的操作,有 Read、Write、或 Read Write 操作。
**********
lock 可选。关键字,说明限定于其它进程打开的文件的操作,有 Shared、Lock Read、Lock Write、和 Lock Read Write 操作。
filenumber 必要。一个有效的文件号,范围在 1 到 511 之间。使用 FreeFile 函数可得到下一个可用的文件号。
reclength 可选。小于或等于 32,767(字节)的一个数。对于用随机访问方式打开的文件,该值就是记录长度。对于顺序文件,该值就是缓冲字符数。
说明对文件做任何 I/O 操作之前都必须先打开文件。Open 语句分配一个缓冲区供文件进行 I/O 之用,并决定缓冲区所使用的访问方式。如果 pathname 指定的文件不存在,那么,在用 Append、Binary、Output、或 Random 方式打开文件时,可以建立这一文件。如果文件已由其它进程打开,而且不允许指定的访问类型,则 Open 操作失败,而且会有错误发生。如果 mode 是 Binary 方式,则 Len 子句会被忽略掉。重要 在 Binary、Input 和 Random 方式下可以用不同的文件号打开同一文件,而不必先将该文件关闭。在 Append 和 Output 方式下,如果要用不同的文件号打开同一文件,则必须在打开文件之前先关闭该文件。
db.Open "Provider=Microsoft.jet.OLeDB.3.51;Data Source=" & App.Path & "\data.mdb;Persist Security Info=False"
Set c = New ADODB.Command
Set c.ActiveConnection = db
SqlString = "Select 图片 From 表"
c.CommandText = SqlString
c.CommandType = adCmdTextdb.Errors.Clear
Set rs = c.Execute
db.Open "Provider=Microsoft.jet.OLeDB.3.51;Data Source=" & App.Path & "\data.mdb;Persist Security Info=False"
Set rs= New ADODB.recordset
SqlString = "Select 图片 From 表"
rs.Open SqlString, db, adOpenForwardOnly, adLockOptimistic
改变锁类型