Query Results Sum

412
1
Jump to solution
03-22-2012 10:39 AM
BrianLeroux
Occasional Contributor III
I have an add-in that queries a Feature Layer and displays results as a graphic layer. I would also like to summarize some of the returned data to display to the user. I am attempting to do sum a single field below and then display in a message box(for now). The field listed below does exist and is returned in the query and is type Double. I get the following error. Any ideas.

 int Sum = featureSet.Features.Select(g => (int)g.Attributes["Cov_A"]).Sum(); MessageBox.Show (Sum.ToString());


Error occured
  at PolicyQuerySpatial.AddIns.QueryDialog.<QueryTask_ExecuteCompleted>b__7(Graphic g)
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.Sum(IEnumerable`1 source)
   at PolicyQuerySpatial.AddIns.QueryDialog.QueryTask_ExecuteCompleted(Object sender, QueryEventArgs args)
   at ESRI.ArcGIS.Client.Tasks.QueryTask.OnExecuteCompleted(QueryEventArgs args)
   at ESRI.ArcGIS.Client.Tasks.QueryTask.<>c__DisplayClass6.<request_Completed>b__4(FeatureSet fs, Exception ex)
   at ESRI.ArcGIS.Client.Tasks.FeatureSet.<>c__DisplayClass2.<FromJsonAsync>b__0(Object s, RunWorkerCompletedEventArgs e)
   at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
   at System.ComponentModel.BackgroundWorker.<OnRun>b__1(Object state)
0 Kudos
1 Solution

Accepted Solutions
BrianLeroux
Occasional Contributor III
FYI..
I solved my own problem by converting double to int32.
int Sum = featureSet.Features.Select(g => Convert.ToInt32(g.Attributes["Cov_A"])).Sum();

View solution in original post

0 Kudos
1 Reply
BrianLeroux
Occasional Contributor III
FYI..
I solved my own problem by converting double to int32.
int Sum = featureSet.Features.Select(g => Convert.ToInt32(g.Attributes["Cov_A"])).Sum();
0 Kudos