public IFeatureLayer  OracleQueryLayer()
        {
            // 创建SqlWorkspaceFactory的对象
            Type pFactoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SqlWorkspaceFactory");

            IWorkspaceFactory pWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(pFactoryType);


            // 构造连接数据库的参数
            IPropertySet pConnectionProps = new PropertySetClass();

            pConnectionProps.SetProperty("dbclient", "Oracle11g");
            pConnectionProps.SetProperty("serverinstance", "esri");
            pConnectionProps.SetProperty("authentication_mode", "DBMS");
            pConnectionProps.SetProperty("user", "scott");
            pConnectionProps.SetProperty("password", "arcgis");

            // 打开工作空间
            IWorkspace workspace = pWorkspaceFactory.Open(pConnectionProps, 0);

            ISqlWorkspace pSQLWorkspace = workspace as ISqlWorkspace;



            //获取数据库中的所有表的名称

            //IStringArray pStringArray= pSQLWorkspace.GetTables();

            //for (int i = 0; i < pStringArray.Count; i++)
            //{
            //    MessageBox.Show(pStringArray.get_Element(i));

            //}

            // 构造过滤条件 SELECT * FROM PointQueryLayer

            IQueryDescription queryDescription = pSQLWorkspace.GetQueryDescription("SELECT * FROM TEST");

            ITable pTable = pSQLWorkspace.OpenQueryClass("QueryLayerTest", queryDescription);

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = pTable as IFeatureClass;

            return(pFeatureLayer);
        }
示例#2
0
        /// <summary>
        /// 从数据库中获取数据表记录
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="whereClause"></param>
        /// <returns></returns>
        public static ITable queryTable(string tableName, string whereClause)
        {
            ISqlWorkspace ws = ArcgisService.openBdcWorkspace() as ISqlWorkspace;

            string            query = "select * from " + tableName + " where 1=1 and " + whereClause;
            IQueryDescription q     = ws.GetQueryDescription(query);

            q.OIDFields = "fId";
            string qName = "";

            ws.CheckDatasetName(tableName, q, out qName);
            if (ws.OpenQueryCursor(query).NextRow() == null)
            {
                return(null);
            }
            ITable table = ws.OpenQueryClass(qName, q);

            return(table);
        }
示例#3
0
        public IFeatureLayer getDcxmLayer(int dcxmId, string tableName)
        {
            ISqlWorkspace ws = ArcgisService.openBdcWorkspace() as ISqlWorkspace;

            string            query = "select * from " + tableName + " where QJDCXM_ID=" + dcxmId;
            IQueryDescription q     = ws.GetQueryDescription(query);

            q.OIDFields    = "fId";
            q.GeometryType = esriGeometryType.esriGeometryPolygon;
            string qName = "";

            ws.CheckDatasetName(tableName, q, out qName);
            ITable table = ws.OpenQueryClass(qName, q);

            IFeatureLayer layer = new FeatureLayer();

            layer.FeatureClass = table as IFeatureClass;
            return(layer);
        }