如题:我把图片保存到sqlserver2000里面了,现在我是通过把二进制写进一个临时文件,在预览,我不想用这种方式,直接看行不行

解决方案 »

  1.   

    用PropertyBag
    Private Sub Command1_Click()
        '新增图片
        Dim Bag As PropertyBag
        Dim buff() As Byte
        Dim cn As ADODB.Connection
        Dim rs As ADODB.Recordset
        
        Set Bag = New PropertyBag
        Bag.WriteProperty "Image", Picture1.Image
        ReDim buff(LenB(Bag.Contents))
        buff = Bag.Contents
        
        'cn 连接数据库略...
        Set rs = New ADODB.Recordset
        rs.Open "select img from tb_image where 1=0", _
            cn, adOpenKeyset, adLockOptimistic
        rs.AddNew
        rs.Fields("img") = buff
        rs.Update
        
        Set rs = Nothing
        Set cn = Nothing
        Set Bag = Nothing
        
        MsgBox "OK"
    End SubPrivate Sub Command2_Click()
        '读出图片
        Dim cn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim Bag As PropertyBag
        Dim buff() As Byte
        
        'cn 连接数据库略...
        Set rs = New ADODB.Recordset
        rs.Open "Select * From tb_image", _
            cn, adOpenKeyset, adLockOptimistic
        
        if Not rs.EOF then
            buff = rs.Fields("Img").Value
            Set Bag = New PropertyBag
            Bag.Contents = buff
            Call Bag.WriteProperty("Image", buff)
            Set Picture1.Picture = Bag.ReadProperty("Image")
            Set Bag = Nothing
        end if
        
    End Sub