A example of "Connect to ArcSDE"

First you should build a  project as follows:

 

 

using  System;
using  System.Drawing;
using  System.Collections;
using  System.ComponentModel;
using  System.Windows.Forms;
using  System.Data;
using  System.IO;
using  System.Runtime.InteropServices;

using  ESRI.ArcGIS.esriSystem;
using  ESRI.ArcGIS.Carto;
using  ESRI.ArcGIS.Controls;
using  ESRI.ArcGIS.ADF;
using  ESRI.ArcGIS.SystemUI;
using  ESRI.ArcGIS.Geodatabase;

namespace  Connect2ArcSDE
{
    
public sealed partial class MainForm : Form
    
{
        
class private members

        
class constructor

        
private void MainForm_Load(object sender, EventArgs e)
        
{
            
//get the MapControl
            m_mapControl = (IMapControl3)axMapControl1.Object;

            
//disable the Save menu (since there is no document yet)
            menuSaveDoc.Enabled = false;

            IWorkspace pWorkspace 
= OpenArcSDEWorkspace("132.1.202.33""5151""sde","sde""sde""SDE.DEFAULT");
            IFeatureWorkspace featureWorkspace 
= (IFeatureWorkspace)pWorkspace;
            FeatureLayer featureLayer 
= new FeatureLayer();
            featureLayer.FeatureClass 
= featureWorkspace.OpenFeatureClass("FCPMDATA.Parcels");//feature name
            featureLayer.Name = featureLayer.FeatureClass.AliasName;
            m_mapControl.AddLayer(featureLayer, 
0);
        }


        
Main Menu event handlers

        
//listen to MapReplaced evant in order to update the statusbar and the Save menu
        private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
        
{
            
//get the current document name from the MapControl
            m_mapDocumentName = m_mapControl.DocumentFilename;

            
//if there is no MapDocument, diable the Save menu and clear the statusbar
            if (m_mapDocumentName == string.Empty)
            
{
                menuSaveDoc.Enabled 
= false;
                statusBarXY.Text 
= string.Empty;
            }

            
else
            
{
                
//enable the Save manu and write the doc name to the statusbar
                menuSaveDoc.Enabled = true;
                statusBarXY.Text 
= Path.GetFileName(m_mapDocumentName);
            }

        }


        
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
        
{
            statusBarXY.Text 
= string.Format("{0}, {1}  {2}", e.mapX.ToString("#######.##"), e.mapY.ToString("#######.##"), axMapControl1.MapUnits.ToString().Substring(4));
        }


        
public IWorkspace OpenArcSDEWorkspace(string server, string instance, string user,string password, string database, string version)
        
{
            ESRI.ArcGIS.esriSystem.IPropertySet propertySet 
= new ESRI.ArcGIS.esriSystem.PropertySetClass();
            propertySet.SetProperty(
"SERVER", server);
            propertySet.SetProperty(
"INSTANCE", instance);
            propertySet.SetProperty(
"DATABASE", database);
            propertySet.SetProperty(
"USER", user);
            propertySet.SetProperty(
"PASSWORD", password);
            propertySet.SetProperty(
"VERSION", version);

            IWorkspaceFactory workspaceFactory 
= new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
            
return workspaceFactory.Open(propertySet, 0);
        }

    }

}

to run the project ,the follow scene you will be see:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值