I am trying to execute SQL queries through both the FeatureSource and QueryTools interfaces and can’t quite figure out how to properly structure it.
An example of the SQL query I am using is
SELECTUNIQUEID
FROM
Layer4
WHERE
( WRK_AREA =
‘14048¬14041¬14045¬34976¬34977¬14052¬14044’
)
I keep getting an OleDbException from the System.Data.DLL saying:
Additional information: The Microsoft Jet database engine could not find the object ‘Layer4’. Make sure the object exists and that you spell its name and the path name correctly.
I know the Layer4 shapefile is there. I am assuming this is set up to work with shapefiles and not just geodatabase tables since it is in the ShapefileFeatureLayer namespace. I normally query the .dbf directly through OleDB, but I have run into encoding problems with the ‘¬’ character we’re using as a delimiter in our WRK_AREA field.
I have tried adding .dbf to the table name, but I have not found any luck yet. Can you provide a working sample for ExecuteQuery to a shapefile? I haven’t been able to find a full one on the site yet. Is there a chance the ExtendedProperties isn’t being set for something for the query?
FeatureSource/QueryTools .ExecuteQuery Questions
Hi Brandon,
Please try attached sample about executing query with QueryTools. This works well on our end, but we haven’t occurred the issue you mentioned. Would you mind provide us the *.dbf file to us for recreating the exception?
BTW, we can get lots of samples for our products from ThinkGeo Product Center. Please choose WPF Desktop from the left list, then click Code Samples and launch “Map Suite Wpf Desktop Edition How Do I samples”. Follow Samples -> Querying Feature Layers -> Sql query a feature layer will get another sample related to executing SQL.
Waiting for your response.
Thanks,
Kevin
Post12570.zip (101 KB)
Hi Kevin… I checked your sample and after getting the right ACE driver, it worked.
I found something peculiar about my project and was wondering if you might be able to shed some light on it. I created a custom class and inherited ShapefileFeatureLayer for it. I am using it to hold the additional information while also doing everything the ShapefileFeatureLayer would do (drawing, editing, etc). I found if I try to run the QueryTools.ExecuteQuery under this class, it fails. However, if I create an instance of ShapefileFeatureLayer (using the properties from my custom class), it will execute. Does this make sense to you? Is there perhaps something in the ShapefileFeatureLayer that doesn’t transfer to child classes?
It doesn’t make sense to me, but I don’t know the components of your classes. My custom class fails with an exception saying it can’t find the table where using the base class ShapefileFeatureLayer works fine. I can create a temporary instance every time I query the shapefile, but I am just curious if there is a particular reason the child classes fail.
Hi Brandon,
Actually, when run
QueryTools.ExecuteQuery, query stuff will complete in ShapefileFeatureSource
rather than ShapefileFeatureLayer itself, so layer inherited from
ShapefileFeatureLayer should also have ShapefileFeatureSource, and the QueryTools
should still work. In other word, you can try to run customizeShapefileFeatureLayer.ExecuteQuery method and see if it works.
Would you mind provide us the code snippet of your customized
ShapefileFeatureLayer as we cannot recreate this issue on our end? Then we can dig into this issue.
Thanks,
Kevin