ODBC connection and Null value Handling Dynamics Ax 2012 R3.

Today I have very small tip to share. I noted down, some odbc connection posts in my blog. All these post shares the code snippets , that used to open odbc connection and did query on SQL server directly. Couple of days ago, I need similar code snippet to read data from SQL server and Insert into another connect. But that code did not had reference to handling null values. So I note down that code snippet too, for future reference.

 

These all odbc connection , command return results in “ResultSet” class.

 

This ResultSet  class has method  “wasnull”. According to documentation, its behavior is strange. First we have to call the get method and then we call “WasNull” to verify that value appears is null or not.

https://msdn.microsoft.com/en-us/library/resultset.wasnull.aspx

 

So whole code snippet will be like.

public void run()
 

{

Connection Con = new Connection();

ResultSet R;

str sql;

Statement Stmt;

SqlStatementExecutePermission permission;

Real _RealValue;

sql = "SELECT * FROM InventTrans ";

Stmt = Con.createStatement();

permission = new SqlStatementExecutePermission(sql);

permission.assert();

R =Stmt.executeQuery(sql);

 

while ( R.next() )

{

_RealValue =R.getReal(1);

if (  R.wasNull(1) ==boolean::false)

{

 

info (" Not null");

}

Else

{

Info (" Null ");

}

 

 

 

}

CodeAccessPermission::revertAssert();

 

}

alirazazaidi

Ali Raza Zaidi, Microsoft ERP Consultant, Currently working for Business Experts Gulf in United Arab Emirates. Specialized in HR & Payroll, Supply Chain and Financials modules.