AO中保存二进制大对象(BLOB)-----将图层保存到数据库中

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

 

http://www.gissky.net/blog/user1/275/archives/2004/642.html 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值