Select to view content in your preferred language

Checking to see if A field has a null value

629
3
Jump to solution
01-16-2012 08:16 AM
DavidAshton
Frequent Contributor
I have created a graphic layer by a attribute/spatial selection tools.  I've created a graphic layer named graphicLayer.  I want to check to see if a field (AsBuiltDate) is null but I'm having trouble with the code/syntax.  Can someone help?

if (graphicsLayer.Graphics.Attributes["AsBuiltDate"] == "NULL")                 {                 }


Thanks
Dave
0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor
You can use query.Where = "NOT (description is NULL)".

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0/query?objectId...

Or if you have already retrieved all features and want to filter the results via client API, you can use linq Query, you can do the following in QueryTask.ExecuteCompleted event handler:
var nonNullValues = from f in e.FeatureSet.Features  where f.Attributes["description"] != null  select f;

View solution in original post

0 Kudos
3 Replies
JMcNeil
Deactivated User
Something like this:

   foreach (Graphic graphic in graphicsLayer.Graphics)
                    {
                        if (graphic.Attributes["AsBuiltDate"] == "Null")
                        {
//DO SOMETHING IF NULL
}
}




JAY
0 Kudos
DavidAshton
Frequent Contributor
Thanks Jay...that got me halfway there. The rest wanted something like  "AsBuilt_Date is NULL" but is was erroring with the null so I did something like graphics1.Attributes["AsBuilt_Date"] is Nullable

my code doesn't crash but it is not working entirely.  I'm trying loop there several graphics and only a few records are null here's what I'm trying to do:

 if (PieChartLayers.SelectedIndex == 3)
                {
                      //      PieChart.Title = "ASBUILT DATE"; AsBuiltDate

                    foreach (Graphic graphics1 in graphicsLayer.Graphics)
                    {

                        if (graphics1.Attributes["AsBuilt_Date"] is Nullable)
                           


                        {



                            Groups1 = graphicsLayer.Graphics.GroupBy(graphic => (DateTime)graphic.Attributes["AsBuilt_Date"],
                                            (date, graphics) => new AttributeGroup
                                           {

                                               Key = date.ToString(),
                                               //   GISDATE = DateTime.ParseExact(date.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture),                            
                                               // Key = String.Format("{0:####-##-##}", date),
                                               Count = graphics.Count(),
                                               //    Sum = graphics.Select(g => (int16)g.Attributes["DOW"]).Sum(),
                                               Graphics = graphics
                                           }).OrderBy(group => group.Key).ToArray();

                        }
                    }
                }



My code doesn't fail now but if doesn't report back the/graph the none null fields.  Maybe I need to assign the null records a value??  Thanks for the help.  Anymore would be much appreciated.

Dave


\
0 Kudos
JenniferNery
Esri Regular Contributor
You can use query.Where = "NOT (description is NULL)".

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0/query?objectId...

Or if you have already retrieved all features and want to filter the results via client API, you can use linq Query, you can do the following in QueryTask.ExecuteCompleted event handler:
var nonNullValues = from f in e.FeatureSet.Features  where f.Attributes["description"] != null  select f;
0 Kudos