dim bit() as byte
后加    
  ReDim Bit(Ado.Recordset.Fields("pic").ActualSize- 1)
试试
    

解决方案 »

  1.   

    dim bit() as byte 
    改成
    dim bit(Ado.Recordset.Fields("pic").ActualSize) as byte
      

  2.   

    dim bit(Ado.Recordset.Fields("pic").ActualSize) as byte 
    好象不能这样定义吧!
      

  3.   

    Public Sub PutFileToDB(rsRecordset As ADODB.Recordset, sField As String, sFileName As String)
        Dim nFileHandle As String
        Dim nFileLen As Long
        Dim abFile() As Byte, nBlocks As Long
        Dim nLoopno As Long
        
        If Dir(sFileName) <> "" Then
            nFileLen = FileLen(sFileName)
            If nFileLen > 0 Then
                nBlocks = (nFileLen - nFileLen Mod MAX_BLOCK_SIZE) / MAX_BLOCK_SIZE
                
                nFileHandle = FreeFile
                Open sFileName For Binary As nFileHandle
                If nBlocks > 0 Then
                    ReDim abFile(0 To MAX_BLOCK_SIZE - 1)
                    For nLoopno = 1 To nBlocks
                        Get nFileHandle, MAX_BLOCK_SIZE * (nLoopno - 1) + 1, abFile
                        rsRecordset.Fields(sField).AppendChunk abFile
                    Next nLoopno
                End If
                
                If nFileLen Mod MAX_BLOCK_SIZE > 0 Then
                    ReDim abFile(0 To nFileLen - nBlocks * MAX_BLOCK_SIZE - 1)
                    Get nFileHandle, nBlocks * MAX_BLOCK_SIZE + 1, abFile
                    rsRecordset.Fields(sField).AppendChunk abFile
                End If
                
                Close nFileHandle
            End If
        End If
    End SubPublic Sub GetFileFromDB(rsRecordset As ADODB.Recordset, sField As String, sFileName As String)
        Dim nFileHandle As String
        Dim nFileLen As Long
        Dim abFile() As Byte, nBlocks As Long
        Dim nLoopno As Long
        
        If Dir(sFileName) <> "" Then
            Kill sFileName
        End If
        
        nFileHandle = FreeFile
        Open sFileName For Binary As nFileHandle
        nFileLen = rsRecordset.Fields(sField).ActualSize
        nBlocks = (nFileLen - nFileLen Mod MAX_BLOCK_SIZE) / MAX_BLOCK_SIZE
        If nBlocks > 0 Then
            ReDim abFile(0 To MAX_BLOCK_SIZE - 1)
            For nLoopno = 1 To nBlocks
                abFile = rsRecordset.Fields(sField).GetChunk(MAX_BLOCK_SIZE)
                Put nFileHandle, MAX_BLOCK_SIZE * (nLoopno - 1) + 1, abFile
            Next nLoopno
        End If
        
        If nFileLen Mod MAX_BLOCK_SIZE > 0 Then
            ReDim abFile(0 To nFileLen - nBlocks * MAX_BLOCK_SIZE - 1)
            abFile = rsRecordset.Fields(sField).GetChunk(UBound(abFile) + 1)
            Put nFileHandle, nBlocks * MAX_BLOCK_SIZE + 1, abFile
        End If
        
        Close nFileHandle
    End Sub
      

  4.   

    public const MAX_BLOCK_SIZE = 1024 '自己定rsRecordset -- 已经打开(如果是GetFileFromDB的话,先定位)的Recordset
    sFiled  --  图片存放在表中的字段名
    sFileName -- 文件名
      

  5.   

    谢了,知道,但我的Image如何加载呢?
      

  6.   

    你不是自己写了吗?!    Set Picbox.Picture = LoadPicture(filetmp ) ‘Picbox是图片框
      

  7.   

    huangpin(hp):
    你说得对,不可以直接这样定义。foolishtiger(吴文智)的方法应该可以。
      

  8.   

    你用UEDIT打开原来的图片文件和从数据库里拿出来的文件有什么区别,我以前试过在数据库拿出来的文件在文件头多了12个字节,在最后多了一个NULL。
    (这两个函数我试过在VB6+SP5+MDB是没有问题的)