Select to view content in your preferred language

Searchin multiple fields using QueryTask

4228
8
01-11-2012 04:35 AM
gabrielvazquez
Deactivated User
Using query task to search a rest service and populate various comboboxes and sorting the results using LINQ. Users can then use the comboboxes and another query task to recieve graphic results from the rest service. This works fine when I query individual fields, however I want to be able to let the user search by multiple comboboxes and I thought I could use a querytask and the query.where option to do so.

For example, something like where GISStateName = 'Maryland' AND GISIncidentType = 'BombThreat'. But in this case it might look something like

query.Text = StateNameCombobox.SelectedItem.ToString() AND IncidentNameComboBox.SelectedItem.ToString(); 

However, I'm not sure if this is even possible or what the correct syntax would be. I have tried a few different ways, but I cant seem to get anything to work.

I can do this with one field, e.g,
query.Text = StateNameComboBox.SelectedItem.ToString();   But not with mutiple field parameters.

Is there a way to use querytask to search multiple fields within a rest service? If so does anyone have any examples. I've looked at the concept and API examples below, but the information I am looking for.

http://help.arcgis.com/en/webapi/silverlight/help/index.html#/Query_task/01660000001t000000/
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AttributeQuery
0 Kudos
8 Replies
DarinaTchountcheva
Frequent Contributor
Gabriel,

You can perform a query using multiple fields, but you will have to use the "Where" property of the "Query" object instead of "Text".

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Quer...


Search the API Reference for more info:

http://help.arcgis.com/en/webapi/silverlight/apiref/api_start.htm
0 Kudos
gabrielvazquez
Deactivated User
darinatch;162367 wrote:
Gabriel,


You can perform a query using multiple fields, but you will have to use the "Where" property of the "Query" object instead of "Text".

Yes, sorry I should have said I have been trying to use query.Where also, however I am still having issues formatting the query. The code states it will accept SQL statements

Where A where clause for the query. Any legal SQL where clause operating on the fields in the layer is allowed, for example: where=POP2000 > 350000 .  
However, there is any more detail and when I try code a simple query.where it does not work. I've tried it various ways, but it continues to not work. Wasnt sure if someone else has had success in using this example.
0 Kudos
gabrielvazquez
Deactivated User
I was able to find the thread below, which helps in better understanding the Query.Where syntax.

http://forums.arcgis.com/threads/28868-Query-Syntax
0 Kudos
gabrielvazquez
Deactivated User
K. I figured it out somewhat. But I wish ESRI would post more information on how to format the "Where" property of the "Query" object.

I was able to do the following, but still trying to figure out how to look at multiple fields.

query.Where = "StateName = '" + StateComboBox.SelectedItem + "'";

or for specific text

query.Where = "StateName = '" + "Maryland" + "'";

This should work for multiple fields, forgot you need &&.

query.Where = "StateName = '" + StateComboBox.SelectedItem+ " ' "  &&  "IncidentType = '" + IncidentTypeComboBox +" ' ";

Just have to fool around with it some more. Actuall the use of the above && operator or &, or AND do not work when searching for strings for multiple fields.
0 Kudos
gabrielvazquez
Deactivated User
Figured it out, was confusing linq and sql. Replaced the && with AND and removed the extra " mark I had before the && operator.

Incorred
query.Where = "StateName = '" + StateComboBox.SelectedItem+ " ' "  &&  "IncidentType = '" + IncidentTypeComboBox +" ' ";

Correct
query.Where = "StateName = '" + StateComboBox.SelectedItem+ " '  AND "IncidentType = '" + IncidentTypeComboBox +" ' ";
0 Kudos
DaveTimmins
Deactivated User
Hi,

I posted a related topic that may be of help here http://davetimmins.wordpress.com/2011/09/09/fluent-where-clause/

Cheers,
0 Kudos
gabrielvazquez
Deactivated User
Hi,

I posted a related topic that may be of help here http://davetimmins.wordpress.com/2011/09/09/fluent-where-clause/

Cheers,


Great link, thank you very much.
0 Kudos
ashash
by
New Contributor
hi...
i'm having the same problem exactly like this..
can someone show me is the code works or not..
please...
0 Kudos