ArcGIS Engine 连接SQL Server并建立关联

IWorkspaceFactory  pWFactory=new OLEDBWorkspaceFactory();

IPropertySet  pPropertySet=new  PropertySetClass();

pPropertySet.SetProperty(“CONNECTSTRING”,”Provider=SQLOLEDB;DataSource=服务器名;Initial Catalog=数据库名;User ID=用户名;Password=密码;”);

IWorkspace  pWorkspace=pWFactory.open(pPropertySet,0);

IFeatureWorkspace  pFWspace=( IFeatureWorkspace)pWorkspace;

ITable pForeignTable=pFWspace.openTable(“表名”);

//join关联外部表

IMap  pMap=AxMapControl1.Map;

ILayer  pLayer=pMap.layer(0);

IFeatureLayer  pFLayer=( IFeatureLayer) pLayer;

IFeatureClass  pFeatureClass=pFLayer.FeatureClass;

IMemoryRelationshipClassFactory  pMemoRelCFactory=new MemoryRelationshipClassFactoryClass();

IRelationshipClass  pRelationshipClass = pMemoRelCFactory.Open (“TableJoin1”,pFClass,”OBJECTID”,(IObjectClass)pForeignTable,  ”OBJECTID”,  ”forward”,  ”backward”, esriRelCardinality.esriRelCardinalityOneToOne);

IDisplayRelationshipClass  pDisplayRelationshipClass=( IDisplayRelationshipClass)pFlayer;

pDisplayRelationshipClass.DisplayRelationshipClass(pRelClass,esriJoinType.esriLeftOuterJoin);

你可能感兴趣的:(ArcGis Engine)