从SDE数据库中读取要素类,并显示在map上
Private Sub getSDELayer()
Dim pMap As IMap
pMap = AxMapControl1.Map
Dim pWorkSF As IWorkspaceFactory
pWorkSF = New SdeWorkspaceFactory
Dim pPropertySet As IPropertySet
pPropertySet = New PropertySet
With pPropertySet
.SetProperty("Server", "zf")
.SetProperty("Instance", "esri_sde")
.SetProperty("user", "sde")
.SetProperty("password", "sde")
.SetProperty("version", "sde.DEFAULT")
End With
Dim pSdeWS As IWorkspace
pSdeWS = pWorkSF.Open(pPropertySet, 0)
Dim pFeatWorkS As IFeatureWorkspace
pFeatWorkS = pSdeWS
Dim pFeatDataset As IFeatureDataset
pFeatDataset = pFeatWorkS.OpenFeatureDataset("SDE.mytest")
Dim pFeatClassContainer As IFeatureClassContainer
pFeatClassContainer = pFeatDataset
Dim i As Integer
For i = 0 To pFeatClassContainer.ClassCount - 1
Dim pFeatClass As IFeatureClass
pFeatClass = pFeatClassContainer.Class(i)
Dim pFeatLyr As IFeatureLayer
pFeatLyr = New FeatureLayerClass
pFeatLyr.FeatureClass = pFeatClass
pFeatLyr.Name = pFeatClass.AliasName
pMap.AddLayer(pFeatLyr)
Next
AxMapControl1.Refresh()
End Sub