[GIS] Help with QueryFilter

arcgis-enginearcobjectsc

I have a query filter which works if pass a new instance of QueryFilterClass without setting any properties. But it breaks if I set the WhereClause. I get an error
0x80040358

queryFilter.WhereClause = "HouseNum = '4501'"; //this is my WhereClause which will make table.Search(queryFilter, true) break

This is my code which works:

IQueryFilter queryFilter = new QueryFilterClass();
//queryFilter.WhereClause = "HouseNum = '4501'";

IQueryFilterDefinition queryFilterDef = (IQueryFilterDefinition)queryFilter;
FileInfo file = new FileInfo(dbfPath);
String dbfDirectoryPath = file.Directory.FullName;
IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
Workspace workspace = workspaceFactory.OpenFromFile(dbfDirectoryPath, 0) as Workspace;
IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
String dbfTable = file.Name;
ITable table = featureWorkspace.OpenTable(dbfTable);

int shapeIndex = table.FindField("Shape");

try
{
using (ComReleaser comReleaser = new ComReleaser())
{
ICursor cursor = table.Search(queryFilter, true);
comReleaser.ManageLifetime(cursor);
IRow row = null;
while ((row = cursor.NextRow()) != null)
{
object o = row.get_Value(shapeIndex);
IPoint p = o as IPoint;
p.Project(gcs); 
double doubleX = p.X;
double doubleY = p.Y; 
}
}
}

How can I fix my WhereClause? Also does QueryFilter support the SQL LIKE Condition?

Best Answer

It is probably best practice to confirm that a field exists before using it in a queryfilter.

This can be done using the ITable.FindField or IFeatureclass.FindField method.

Related Question