Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 17314

Handling null values in dataset and DataReader in Dynamics ax 2012

$
0
0

 

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”);

}


Viewing all articles
Browse latest Browse all 17314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>