Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
1  
what line does it throw the exception on? –  Kirk Kuykendall Apr 25 '11 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? –  Michael Todd Apr 25 '11 at 17:17
    
@Kirk Kuykendall It throws the exception on this line, table.Search(queryFilter, true) –  patrick Apr 25 '11 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? –  Kirk Kuykendall Apr 25 '11 at 17:24
2  
What does table.FindField("HouseNum") return? –  Kirk Kuykendall Apr 25 '11 at 17:37

4 Answers 4

up vote 2 down vote accepted

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"

http://nicogis.blogspot.com/2010/02/server-context-empty.html

EDIT #2:

Also try setting the SubFields.

queryFilter.SubFields = "HouseNum";

share|improve this answer
1  
IMO servercontext is a red herring. –  Kirk Kuykendall Apr 25 '11 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 '11 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 '11 at 21:58

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.

share|improve this answer
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 '11 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
-2147220648L
>>>

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.

share|improve this answer

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

share|improve this answer
    
based on earlier questions, he doesn't have desktop - just arcengine. –  Kirk Kuykendall Apr 25 '11 at 18:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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