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");

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

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

  • 1
    what line does it throw the exception on? Apr 25, 2011 at 17:13
  • Could it be that HouseNum is not a valid column name for that layer, or that the data type is an integer and not a string? Apr 25, 2011 at 17:17
  • @Kirk Kuykendall It throws the exception on this line, table.Search(queryFilter, true)
    – patrick
    Apr 25, 2011 at 17:21
  • 1
    HouseNum seems like it might be a numeric field, in which case you would get an error. Have you confirmed that it is a text field? Apr 25, 2011 at 17:24
  • 2
    What does table.FindField("HouseNum") return? Apr 25, 2011 at 17:37

4 Answers 4


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.

  • 1
    +1 Validating the data model (at least on the column naming level) is a good thing to do before letting your code proceed any futher. If you do not do that, you risk getting a non-informative exception later, making the code much harder to debug.
    – Petr Krebs
    Apr 25, 2011 at 21:52

I often see people asking how to figure out what "erro x" is. So even though someone already potentially answered this question, I will still show you how decode the HRESULT value.

All you have to do is grab the hex number, interpret it as a signed 32 bit number, and then search for it on google (or the ESRI site). If it is a GDB error, it will show up as on of the value in the FDO error constant or the sdeErro constants. I just use python like so:

rburhum@Router-MBP.local ~ $ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> i = 0x80040358
>>> s32 = (i + 2**31) % 2**32 - 2**31
>>> s32

As you can see, the error is -2147220648 , if you are using a search engine, search for 2147220648 (without the minus) because search engines usually have a meaning for the minus in front.

Right away, my google search shows an fdoError constant as a result.

FDO_E_TABLE_COLUMN_NOT_FOUND    -2147220648 A column was specified that does not exist.

The table you are querying does not have the field you want.


Yes it does support the LIKE. Try this:

queryFilter.WhereClause = "HouseNum LIKE '4501'";

EDIT #1:

Also you might want to try using the "serverContext.CreateObject"


EDIT #2:

Also try setting the SubFields.

queryFilter.SubFields = "HouseNum";

  • 1
    IMO servercontext is a red herring. Apr 25, 2011 at 18:11
  • I believe Kirk's answer is more correct in the context of what was asked and how it was solved and should be the one marked as accepted.
    – Petr Krebs
    Apr 25, 2011 at 21:48
  • The query format and capabilities in terms of supported clauses and constructs is always determined by the underlying storage. One needs to be careful since the exact syntax for LIKE differs for, say, shapefiles and personal geodatabases. The ISQLSyntax interface provides the necessary information.
    – Petr Krebs
    Apr 25, 2011 at 21:58

Open the Select by Attributes dialog, manually create the query, and compare that syntax with your WhereClause.

  • based on earlier questions, he doesn't have desktop - just arcengine. Apr 25, 2011 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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