≡ Menu




Handling null values in dataset and DataReader in Dynamics ax 2012

 

In X++ we can use System.Data.SqlClient.SqlReader or System.Data.DataSet, to Query on external database. But unfortunately there is No isDBNull function available for checking the null and same time system.string().isnullorempty and CLRInterop::Null is not work.

 

If you are using dataset or datatable then use datarow’s is null method

For example

 

If (!DataRow.isNull(“FirstName”)

{

Info(DataRow.get_Item(“FirstName”);

}

 

Second way to use the index of column according to field name in query, It is zero based index

If (!DataRow.isNull(0)

{

Info(DataRow.get_Item(“FirstName”);

}

 

If use data reader then use data reader is dbnull method, this method takes the index of field, there is no overload method for field Name,

 

int columnNum = datareader.GetOrdinal(“FirstName”);
if (datareader.IsDBNull(columnNum))
{
Info(datareader.get_item(“FirstName”);

}

{ 0 comments… add one }

Leave a Comment