(轉載)VB 查詢Oracle中blob類型欄位,並且把blob中的圖片以流的方式顯示在Image上

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   cti   代碼   

原文摘自:http://heisetoufa.iteye.com/blog/504068
‘模組代碼Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlobal As Long, ByVal fDeleteOnRelease As Long, ppstm As Any) As LongPrivate Declare Function OleLoadPicture Lib "olepro32" (pStream As Any, ByVal lSize As Long, ByVal fRunmode As Long, riid As Any, ppvObj As Any) As LongPrivate Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As Any) As LongPrivate Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As LongPrivate Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As LongPrivate Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As LongPrivate Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As LongPublic Type GUID ‘ 16 bytes (128 bits)‘dwData1 As Long ‘ 4 bytes‘wData2 As Integer ‘ 2 bytes‘wData3 As Integer ‘ 2 bytesabData4(7) As Byte ‘ 8 bytes, zero basedEnd TypePublic Function PictureFromByteStream(B() As Byte) As IPicture    Dim hMem        As Long    Dim lpMem       As Long    Dim LowerBound  As Long    Dim ByteCount   As Long    Dim IID_IPicture As GUID    Dim istm        As stdole.IUnknown        LowerBound = LBound(B)    ByteCount = UBound(B) - LowerBound + 1        hMem = GlobalAlloc(&H2, ByteCount)        If hMem <> 0 Then                lpMem = GlobalLock(hMem)                If lpMem <> 0 Then                        MoveMemory ByVal lpMem, B(LowerBound), ByteCount                        GlobalUnlock hMem                        If CreateStreamOnHGlobal(hMem, 1, istm) = 0 Then                                If CLSIDFromString(StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"), IID_IPicture) = 0 Then                                        OleLoadPicture ByVal ObjPtr(istm), ByteCount, 0, IID_IPicture, PictureFromByteStream                                    End If                            End If                    End If            End If    End Function
Public Sub Combo1_Click()Dim adoCnn As ADODB.Connection    Dim rstOra As ADODB.Recordset    Dim intI   As Integer         Set adoCnn = New ADODB.Connection    Set rstOra = New ADODB.Recordset                                         adoCnn.ConnectionString = "Provider=OraOLEDB.Oracle;User ID=dzjc;password=zlkj;Data Source=dzjc_2005;" ‘讀blob欄位要用Provider=OraOLEDB.Oracle             adoCnn.CursorLocation = adUseClient    adoCnn.Open               rstOra.CursorLocation = adUseClient       rstOra.ActiveConnection = adoCnn    rstOra.Open "SELECT zp FROM dzjc.dzjc_wfzp WHERE xh = ‘5‘"              ‘Set Image1.DataSource = rstOra              Set Image1.Picture = PictureFromByteStream(rstOra.Fields("zp").Value)End Sub

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.