zoukankan      html  css  js  c++  java
  • AO中保存二进制大对象(BLOB)

    示例代码演示如何保存一个.lyr文件,作为资料保存

    //保存
    Private Sub UIButtonControl1_Click()
    ' Get the IPersistStream for the first layer from the map
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument

    Dim pPersist As IPersistStream
    Set pPersist = pMxDoc.FocusMap.Layer(0)

    ' Now persist the layer to the memory BLOB stream
    Dim pMemoryStream As IMemoryBlobStream
    Set pMemoryStream = New MemoryBlobStream

    pPersist.Save pMemoryStream, False

    ' Finally, save the BLOB into the database
    Dim pWorkspaceFactory As IWorkspaceFactory
    Set pWorkspaceFactory = New AccessWorkspaceFactory

    Dim pFeatureWorkspace As IFeatureWorkspace
    Set pFeatureWorkspace =
    pWorkspaceFactory.OpenFromFile("C:\Source\BLOB.mdb", 0)

    Dim pTable As ITable
    Set pTable = pFeatureWorkspace.OpenTable("MyLayers")

    Dim pRow As IRow
    Set pRow = pTable.CreateRow

    pRow.Value(pRow.Fields.FindField("Layers")) = pMemoryStream
    pRow.Store
    End Sub


    //读取
    Private Sub UIButtonControl2_Click()
    Dim pWorkspaceFactory As IWorkspaceFactory
    Set pWorkspaceFactory = New AccessWorkspaceFactory

    Dim pFeatureWorkspace As IFeatureWorkspace
    Set pFeatureWorkspace =
    pWorkspaceFactory.OpenFromFile("C:\Source\BLOB.mdb", 0)

    Dim pTable As ITable
    Set pTable = pFeatureWorkspace.OpenTable("MyLayers")

    Dim pCursor As ICursor
    Set pCursor = pTable.Search(Nothing, False)

    Dim pRow As IRow
    Set pRow = pCursor.NextRow

    If (pRow Is Nothing) Then Exit Sub

    Dim pMemoryStream As IMemoryBlobStream
    Set pMemoryStream = pRow.Value(pRow.Fields.FindField("Layers"))


    Dim pLayer As ILayer
    Set pLayer = New FeatureLayer

    Dim pPersist As IPersistStream
    Set pPersist = pLayer

    pPersist.Load pMemoryStream

    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument

    pMxDoc.FocusMap.AddLayer pLayer
    End Sub
  • 相关阅读:
    题解 AT5228 【[ABC162A] Lucky 7】
    题解 P6467 【[COCI2008-2009#6] BUKA】
    2020 Codeforces 愚人节比赛题解 A~D
    题解 AT4251 【[ABC110A] Maximize the Formula】
    题解 AT5638 【November 30】
    题解 AT4164 【[ABC102A] Multiple of 2 and N】
    多项式全家桶
    烂题推荐
    NOIP 2020 游记
    P5048 题解
  • 原文地址:https://www.cnblogs.com/linghe/p/1389952.html
Copyright © 2011-2022 走看看