AnsweredAssumed Answered

How to I get OpenQueryTable to work?

Question asked by BradleyJones on Jan 25, 2019
Latest reply on Feb 8, 2019 by BradleyJones

Trying this as a Question instead of a Discussion.

 

I'm having trouble getting a QueryTable to display.  The tool selects a single sewer line, gets the feature ID for the line (called COMPKEY), then uses the ID to build the where clause and hopefully open the query table. 

 

What am I missing?

 

 protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
        {
            Uri path = new Uri("O:\\P\\A\\T\\H\\CONNECTION.sde");
            return QueuedTask.Run(() =>
            {
                ActiveMapView.SelectFeatures(geometry, SelectionCombinationMethod.New);

                string slComp = Module1.GetCompkey();
                if (!string.IsNullOrEmpty(slComp))
                {
                    // Set up Geodatabase Object)
                    using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(path)))
                    {
                        string queryString = $"COMPKEY = {slComp}";
                        QueryDef queryDef = new QueryDef()
                        {
                            Tables = "SDE.TABLE.NAME",
                            WhereClause = queryString,
                        };

                        QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
                        {
                            MakeCopy = true,
                            Name = $"Preventive Maintenance: {slComp}.",
                            PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("SDE.sewerman.tblV8PMTOOL", "COMPKEY")
                        };

                        var queryTable = geodatabase.OpenQueryTable(queryTableDescription);

                        int count = queryTable.GetCount();
                        if (count == 0)
                        {
                            MessageBox.Show("Sewer line selected has no preventive maintenance scheduled.");
                        }

                        else
                        {
                            // Used since query table doesn't display
                            // MessageBox.Show($"Row count: {count}");
                        }
                    }
                };

Outcomes