http://giscolor.bokee.com/viewdiary.40978046.html

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//ESRI
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;

// ArcGIS Engine引用
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.ToolbarControl;
using ESRI.ArcGIS.TOCControl;
//using ESRI.ArcGIS.MapControl;
using ESRI.ArcGIS.PageLayoutControl;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.GlobeCore;
using System.Runtime.InteropServices;

  /// <summary>
        /// 连接sde数据库,并设定map的图层
        /// </summary>
        private void GetSdeData()
        {
            /**连接sde数据库**/
            //License
            IAoInitialize pAoInit = new AoInitializeClass();
            pAoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);

            //Workspace
            IWorkspaceFactory pWorkspaceFactory;
            pWorkspaceFactory = new SdeWorkspaceFactoryClass();

            //PropertySet
            IPropertySet pPropertySet;
            pPropertySet = new PropertySetClass();
            pPropertySet.SetProperty("Service", "esri_sde");
            pPropertySet.SetProperty("Server", "192.168.25.110");
            //pPropertySet.SetProperties("Database","wjgis");
            pPropertySet.SetProperty("Instance", "port:5151");
            pPropertySet.SetProperty("user", "sangis");
            pPropertySet.SetProperty("password", "sangis");
            pPropertySet.SetProperty("version", "sde.DEFAULT");

            //IFeatureWorkspace对象
            IFeatureWorkspace pSdeWorkspace;

            IFeatureDataset pFeatureDataset;
            IFeatureClass pFeatureClass;

            //图层
            IFeatureLayer layer;


            try
            {
                //连接
                pSdeWorkspace = (IFeatureWorkspace)pWorkspaceFactory.Open(pPropertySet, 0);
                //取数据
                pFeatureClass = pSdeWorkspace.OpenFeatureClass("TV井盖");
                //定义图层
                layer = new FeatureLayerClass();
                //设定layer的FeatureClass属性
                layer.FeatureClass = pFeatureClass;
                //设定Map的图层
                MapControl.Map.AddLayer(layer);
            }
            catch (Exception ex)
            {

                MessageBox.Show("SDE数据库不能连接!" ex.Message);
                //text_sqlfilter.Text = ex.Message;
            }
        }

posted on 2010-10-16 14:54  hl3292  阅读(584)  评论(0编辑  收藏  举报