设置为image字段,或二进值字段,有关操作方法,很多地方都有源代码

解决方案 »

  1.   

    access字段用ole对象,利用appendchunk和getchunk方法可以保存和得到图片
      

  2.   

    Access 中是 OLE 对象的字段
    把代码也给你吧:
    Private Sub DBOpen()
        'open the database with ADO
        MYcon.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0; DATA SOURCE=" & App.Path + "/DBpic.MDB"
        MYrs.Open "PICTABLE", MYcon, 1, 3End Sub
    'Close the open database
    Private Sub DBClose()
        MYrs.Close
        MYcon.Close
        Set MYrs = Nothing
        Set MYcon = Nothing
    End SubPrivate Sub SaveInto(ByVal strPath As String)Dim lngFileLength   As Long   'the length of the file
    Dim lngBlockCount   As Long   'the number of total whole block
    Dim lngLastBlock   As Integer   'the length of the last block
    Dim lngBlockIndex   As Long   'the index of each block
    Dim ByteGet()   As Byte   '用于传送数据的二进制数组
    Dim FileNum As Integer 'return the file number which the next file will use
    Dim strFilepath As String
            
            strFilepath = strPath
            FileNum = FreeFile()
            
            Open strFilepath For Binary Access Read As #FileNum
            lngFileLength = LOF(FileNum) '返回一个 Long,表示用 Open 语句打开的文件的大小,该大小以字节为单位。
            lngBlockCount = lngFileLength \ lngBlockSize
            lngLastBlock = lngFileLength Mod lngBlockSize
            
            MYrs.AddNew
                MYrs.Fields("size") = lngFileLength
                MYrs.Fields("date") = Date
                MYrs.Fields("name") = Trim(Text1)
                ReDim ByteGet(lngBlockSize)
                For lngBlockIndex = 1 To lngBlockCount
                    Get #FileNum, , ByteGet()
                    MYrs.Fields("pic").AppendChunk ByteGet()
                Next
        
            If lngLastBlock > 0 Then
                ReDim ByteGet(lngLastBlock)
                Get #FileNum, , ByteGet()
                MYrs.Fields("pic").AppendChunk ByteGet()
            End If
                MYrs.Update
            Close #FileNum
    End SubPrivate Sub ShowImg(ByVal RecordPoint As Long)
    On Error Resume NextDim temp_path As String
    Dim temp_file As String
    Dim length As Long
    Dim lngFileLength   As Long   'the length of the file
    Dim lngBlockCount   As Long   'the number of total whole block
    Dim lngLastBlock   As Integer   'the length of the last block
    Dim lngBlockIndex   As Long   'the index of each block
    Dim ByteGet()   As Byte   '用于传送数据的二进制数组
    Dim FileNum As Integer 'return the file number which the next file will use
    Dim strFileName As Stringtemp_path = Space$(MAX_PATH)
    length = GetTempPath(MAX_PATH, temp_path)
    temp_path = Left$(temp_path, length)
    temp_file = Space$(MAX_PATH)
    GetTempFileName temp_path, "per", 0, temp_file
    strFileName = Left$(temp_file, InStr(temp_file, Chr$(0)) - 1)    MYrs.MoveFirst
        MYrs.Move RecordPoint
        Label1 = MYrs.AbsolutePosition
        frmMain.Caption = MYrs.Fields("name") + Str(i)
        FileNum = FreeFile()
        Open strFileName For Binary As #FileNum
        lngFileLength = MYrs.Fields("size")
        lngBlockCount = lngFileLength \ lngBlockSize
        lngLastBlock = lngFileLength Mod lngBlockSize
        For lngBlockIndex = 1 To lngBlockCount
            ByteGet() = MYrs.Fields("pic").GetChunk(lngBlockSize)
            Put #FileNum, , ByteGet()
        Next
        If lngLastBlock > 0 Then
        ReDim ByteGet(lngLastBlock)
            ByteGet() = MYrs.Fields("pic").GetChunk(lngBlockSize)
            Put #FileNum, , ByteGet()
        End If
        
        Picture1.Picture = LoadPicture(strFileName)
        
        Close #FileNum
        Kill strFileName
        
        Err.Clear
    End SubPrivate Sub AimFilePath(ByVal strPath As String)
    Dim PathVal As String
        PathVal = Dir(strPath)
        If PathVal = Null Then MsgBox "null"
        Do While PathVal <> ""
            SaveInto (strPath + PathVal)
            PathVal = Dir
        Loop
    End Sub