Select to view content in your preferred language

Cannot pass the DateTime value to ArcGIS query in silverlight!

918
2
12-01-2011 08:56 AM
AnhTruong
Emerging Contributor
Please advice me whether or not I can pass the DateTime value to QueryTask in ESRI.ArcGIS query???

My Silverlight page have a DatePicker, Textbox and Search button. When I select a date to binding the value to textbox. I would like to pass datetime value to ArcGIS query as following:

========================================================================

string paramStartDate;
paramStartDate = txtStartName.Text;
DateTime dtStartDate = Convert.ToDateTime(paramStartDate);

// if I selected the date from DatePicker is 7/30/2010, I can trace the selected value using VS 2010 //debugging with System.DateTime datatype {7/30/2011 12:00:00 AM}

QueryTask queryTask = new QueryTask(URLService);
queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
queryTask.Failed += QueryTask_Failed;

ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
query.OutFields.Add("*");
//This query cannot return the records even though they existed in database
string querySearch = "TIME_FINISH >= TO_DATE(dtStartDate, 'MM/DD/YYYY HH:MI:SS AM')";
// but this query is working if I do hard code
//string querySearch = "TIME_FINISH >= TO_DATE('7/30/2011 12:00:00 PM', 'MM/DD/YYYY HH:MI:SS AM')";

query.Where = querySearch;
queryTask.ExecuteAsync(query);

======================================================================
I debugged the Silverlight and using Add Watch for looking the value dtStartDate, for example if I selected 10/8/2011 from calendar of DatePicker and can see the value of dtStartDate is {8/12/2011 12:00:00 AM} with System.DateTime datatype. Then step into the querySearch string, but I can not see the actual value of dtStartDate. That why my QueryTask execute without any returned records. Is it any way to do it in ArcGIS API for Silverlight??? Your prompt helps are much appreciated. Thanks in advance.
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
//This query cannot return the records even though they existed in database
string querySearch = "TIME_FINISH >= TO_DATE(dtStartDate, 'MM/DD/YYYY HH:MI:SS AM')";

The server doesn't know your 'dtStartDate' variable so you have to replace it by its value:

string querySearch = "TIME_FINISH >= TO_DATE('" +
dtStartDate.ToString("MM/dd/yyyy hh:mm:ss tt") +
"', 'MM/DD/YYYY HH:MI:SS AM')";
0 Kudos
AnhTruong
Emerging Contributor
Super thanks. It works very well.


The server doesn't know your 'dtStartDate' variable so you have to replace it by its value:

string querySearch = "TIME_FINISH >= TO_DATE('" +
dtStartDate.ToString("MM/dd/yyyy hh:mm:ss tt") +
"', 'MM/DD/YYYY HH:MI:SS AM')";
0 Kudos