This is some code that I am using to try to get a working IFeatureLayer from a subset of data from a database table. The fourth line containing "fcWkspc.OpenFeatureQuery" throws and error complaining about an "The operation was attempted on an empty geometry.".

Should also mention that this code was lifted directly from ESRI documentation example code at the following link:


Can anyone tell me what I might be doing wrong?

// m_wkSpace2 is of type IWorkspace2
IFeatureWorkspace fcWkspc = (IFeatureWorkspace)m_wkSpace2;

IQueryDef qDef = fcWkspc.CreateQueryDef();

Def.Tables = "dbo.TABLE_NAME";
qDef.WhereClause = "Name1 = '" + var1 + "' AND Name2 = '" + var2 + "'";

IFeatureDataset featureDataset = fcWkspc.OpenFeatureQuery("MyJoin", qDef);
IFeatureClassContainer featureClassContainer = (IFeatureClassContainer)featureDataset;
IFeatureClass featureClass = featureClassContainer.get_ClassByName("MyJoin");

IFeatureLayer layerForMap = (IFeatureLayer)featureClass;

1 Answer 1


I would first check to see if your where clause is valid and it does return data. Another suggestion would be to use the IFeatureLayerDefinition to setup a QueryDef since you are only using a single table - An example here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.