xudanfu
路人甲
路人甲
  • 注册日期2004-05-30
  • 发帖数48
  • QQ
  • 铜币303枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1033回复:0

[转帖]

楼主#
更多 发布于:2004-08-21 11:55
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
喜欢0 评分0
游客

返回顶部