How do I obtain a NULL value from an ArcGIS.Core.Data.Row?
I have a nullable field "Timestamp" in the Database.
When I iterate using a RowCursor, I can find no way to obtain that NULL value using the ArcGIS Pro SDK for DotNet.
I get a valid Row object and I can access all the other fields using the Indexer, just not the NULL field!
Something like this:
while(cursor.MoveNext()) { Row row = cursor.Current; DateTime timestamp = (DateTime)row["Timestamp"]; //Works only if not NULL. Throws NullReferenceException otherwise }
Hi Gernot,
You can assign row value to object type variable. Then check if it is null. If not - assing it to timestamp variable as in your code.
Another way is to use Convert.ToDateTime like this:
DateTime timestamp = Convert.ToDateTime(row["Timestamp"]);
Hi Gintautas,
thanks very much for your quick reply. That solved the problem for me!
I have to admit I didn't take into account that, in DotNet, a cast from null to another type can actually fail - if that type is a struct!
I guess that programming Java for 20+ years has spoiled me somehow
Regards,
Gernot
I used the following snippet to check if a column value of a Row is null:
foreach (var field in fields)
{
var val = row[field.Name];
if (val is DBNull || val == null) continue;
...
}
the code is used in this sample: https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/2d6a30e2597c7a0079ae65b182f60a77e79aae...
The sample has to ignore null columns.