How to pass NULL values from an IDBStatemwnt

With the following Delphi code in an Aurelius Server application

var
AStatement: IDBStatement;
AData: IDBResultSet;
begin
try
AStatement := Manager.Connection.CreateStatement;
AStatement.SetSQLCommand(rsSQL);
AData := AStatement.ExecuteQuery;
if AData.Next then
begin
Result := TWebFarmField.Create;
Result.ID:= AData.GetFieldValue('ID');
Result.InspectionsID:= AData.GetFieldValue('InspectionsID');
...
end;

I am seeing an error in the line "Result.InspectionsID:= ..."

The error states that AData.GetFieldValue('InspectionsID') is NULL

My Result.InspectionsID is defined as Nullable

type
TWebFarmField = class
ID: Integer;
InspectionsID: Nullable;
...

And I need to be able to pass NULL values into the Result.

How can I cope with this situation?

You could use

uses System.Variants;

if VarIsNull(AData.GetFieldValue('InspectionsID')) then
//....
else
Result.InspectionsID:= AData.GetFieldValue('InspectionsID');
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.