读出:        Dim bit1() As Byte
        On Error GoTo Err1:
        bit1 = r("zp").GetChunk(r("zp").ActualSize)
        '然后将字节数组的内容拼装成文件即可
        Open App.Path & "\temp.jpg" For Binary As #1
        Put 1, 1, bit1
        Close 1
    Image1.Stretch = False
    Image1 = LoadPicture(App.Path & "\temp.jpg")
写入:        Open Image1.Tag For Binary As #1
        ReDim bit(LOF(1)) As Byte
        Get 1, 1, bit
        Close 1
        r.Open "select * from byzl where kh='" & Trim(Txtkh) & "'", Cn, adOpenKeyset, adLockOptimistic
        r("zp").AppendChunk bit
        r.Update
        r.Close

解决方案 »

  1.   

    感谢您使用微软产品。另外一种方法是使用ADO对象的Stream 对象。下面的代码供您参考:Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim stm As New ADODB.StreamWith cn
      .ConnectionString = "Provider=SQLOLEDB.1;User ID=<user name>;Password=<Password> ;Initial Catalog=<Database Name Here>;Data Source=<SQL Server Name Here>"
      .Open
    End Withrs.Open "select Photo from table5 where ID=1", cnWith stm
      .Type = adTypeBinary
      .Open
      .Write rs!Photo
      .SaveToFile "c:\test.xxx", adSaveCreateOverWrite
    End Withstm.Close
    rs.Close
    cn.CloseEnd Sub注意:要使用stream 对象, 您需要使用ADO 2.5 或以上版本。详细信息请参看下面的文章:
    http://support.microsoft.com/support/kb/articles/Q258/0/38.ASP
    http://www.microsoft.com/Office/techinfo/productdoc/2002/en/excel/ado210/mdobjstream.htm- 微软亚洲技术中心 VB技术支持本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款 (http://www.csdn.net/microsoft/terms.shtm)。
      

  2.   

    请问ACPTVB,如何不用绑定的方式,直接把数据库中的图片(.bmp,.jpg等)显示在屏幕上?(不用临时文件)
    谢谢!