Query FGDB Feature Class from C#.NET Application

1171
1
04-17-2012 08:49 PM
ShaunWeston
Occasional Contributor
I've never really done any ArcObjects development before and just looking for some advice. I have built a C#.NET application and I want that to be able to read the attribute data from a feature class in a file geodatabase and just wondering exactly how to do that?

Would using this example I found be the best way to go?

I'm not exactly sure how to define the geodatabase and the table in this though?

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Querying_geodatabase_ta...



            // Create the query filter.
            IQueryFilter queryFilter = new QueryFilterClass();


            // Select the fields to be returned�??the name and address of the businesses.
            queryFilter.SubFields = "NAME, ADDRESS";


            // Set the filter to return only restaurants.
            queryFilter.WhereClause = "TYPE = 'Restaurant'";


            // Use the PostfixClause to alphabetically order the set by name.
            IQueryFilterDefinition queryFilterDef = (IQueryFilterDefinition)queryFilter;
            queryFilterDef.PostfixClause = "ORDER BY NAME";


            // Output the returned names and addresses.
            int nameIndex = table.FindField("NAME");
            int addressIndex = table.FindField("ADDRESS");
            using (ComReleaser comReleaser = new ComReleaser())
            {
                ICursor cursor = table.Search(queryFilter, true);
                comReleaser.ManageLifetime(cursor);
                IRow row = null;
                while ((row = cursor.NextRow()) != null)
                {
                    String name = Convert.ToString(row.get_Value(nameIndex));
                    String address = Convert.ToString(row.get_Value(addressIndex));
                    Console.WriteLine("{0} - {1}", name, address);
                }
            }
0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor
Take a look at these topics in the help about connecting to a geodatabase and opening a table
0 Kudos