• 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
  • 相关阅读:
    Javascript面向对象编程--原型字面量
    Javascript面向对象编程--原型(prototype)
    Javascript面向对象编程--封装
    java word操作
    uniapp获取mac地址,ip地址,验证设备是否合法
    element-ui+vue表单清空的问题
    mysql,oracle查询当天的数据
    vue+element在el-table-column中写v-if
    idea修改页面不用重启项目(转)
    vue+element实现表格v-if判断(转)
  • 原文地址:https://www.cnblogs.com/linghe/p/1389952.html
Copyright © 2020-2023  润新知