Select to view content in your preferred language

ArcObjects QueryDef PrefixClause - using 'TOP'

3634
7
Jump to solution
10-11-2010 10:00 AM
MelodyMeinhardt
Deactivated User
This is a .NET project and I am building a query definition and tried using 'TOP' in the PrefixClause, but it generates an error 'Invalid parameter value passed to function'. This is what my code looks like:

Dim queryFilterDef As IQueryDef2 = CType(_featureWorkspace.CreateQueryDef, IQueryDef2)
With queryFilterDef
   .WhereClause = searchString
   .PrefixClause = "TOP 1 " & featureClass.OIDFieldName
End With
Can TOP be used, and if so, what is the syntax?
My objective is just to determine that there is at least one record - I do not want records returned, or at least no more than one record.
0 Kudos
1 Solution

Accepted Solutions
LanceShipman
Esri Regular Contributor
I am using ArcSDE/sql express right now.  We also have some data in a file geodatabase where I have the same needs.


TOP will not work with File Geodatabase as it's not part of the current SQL implementation. In preliminary testing using top as PrefixClause does not appear to work for SQL Server. I need to do some more testing to see if it's a bug.

You could just use IFeature.FeatureCount to see is any rows will be returned by your query.

View solution in original post

0 Kudos
7 Replies
ThavitinaiduGulivindala
Regular Contributor
Hi Meinmel,

why dont you use ITable.RowCount method to get the number of records?
0 Kudos
GregRieck
Frequent Contributor

FYI ITable.RowCount does take an IQueryFilter as a parameter. You could pass your query and determine the number of rows.

ArcObjects Help for .NET developers

0 Kudos
MelodyMeinhardt
Deactivated User
Thanks for the response!  I don't want the number of records in the table, I want to know if any records exist with the search criteria that is entered.  For example, I want to know if there are any businesses with a name like '% RIVER%'.  I don't want how many records meet that criteria, I just want to know if at least one record meets that criteria.
0 Kudos
LanceShipman
Esri Regular Contributor
What data source are you using (File Geodatabase, ArcSDE(Oracle, Informix, SQL Server, DB2, PostgreSQL), Personal Geodatabase or ?
0 Kudos
MelodyMeinhardt
Deactivated User
I am using ArcSDE/sql express right now.  We also have some data in a file geodatabase where I have the same needs.
0 Kudos
LanceShipman
Esri Regular Contributor
I am using ArcSDE/sql express right now.  We also have some data in a file geodatabase where I have the same needs.


TOP will not work with File Geodatabase as it's not part of the current SQL implementation. In preliminary testing using top as PrefixClause does not appear to work for SQL Server. I need to do some more testing to see if it's a bug.

You could just use IFeature.FeatureCount to see is any rows will be returned by your query.
0 Kudos
MelodyMeinhardt
Deactivated User
Ok, thanks, I will give that a try.  I was trying to find a way to code it that was faster then what I'm seeing.
0 Kudos