最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

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

 

}
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址