我看过一个Access的历程,直接给一个绑定到数据库的IMAGE控件设置pirture属性,就可以了
我想Sql也应该一样,应该由数据控件办理了吧

解决方案 »

  1.   

    使用MS DATA CONTROL 绑定到IMMIGE字段即可。
      

  2.   

    如果是
    图片文件操作的!
    我又一个组件可以实现存入数据库(ADO)!
    读取当然很简单了!
    用steam!
      

  3.   

    '这代码是 CSDN 以前吴蚊子的,他很少上CSDN了。但他的代码还是给了不少人以帮助'存文件到数据库
    Const BLOCKSIZE = 4096 '每次读写块的大小Public rsBinary As New ADODB.Recordset
    Public Function AddFile(ByVal FileID As Long)
        '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
                TypeCode = Right(.filename, 3)
                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.Fields("id") = FileID
                rsBinary.Update
                rsBinary.UpdateBatch
                Close #1
                
                AddFile = True
                MsgBox "Save finished", vbInformation
            Else
                AddFile = False
            End If
        End With
        Exit Function
    ErrorHandle:
        AddFile = False
    End 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.Requery
        rsBinary.MoveFirst
        rsBinary.Find " id=" & FileID
        
        If Not rsBinary.EOF Then
            With frmBinary.CommonDialog1
                .filename = "TempSave" & "." & rsBinary.Fields("typecode")
                '.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 Sub
    ErrorHandle:
        
    End Sub