web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

System.DBNull.Value is not available

(0) ShareShare
ReportReport
Posted on by

As part of integration with another system I use System.Data.SqlClient library to create a command object and pass parameters on to it. One of the parameters every once in a while will get a DBNull.Value. It seems that AX does not offer a way to make static get_Value() call directly on the DBNull type. So the code like this won't compile:

System.DBNull nullValue = System.DBNull::get_Value();

Any idea how else I can do what I need?

*This post is locked for comments

I have the same question (0)
  • Vilmos Kintera Profile Picture
    46,149 on at

    AX does not use SQL Server's null values in the fields, it is always an empty string, 0, or 1900-01-01 00:00 for dates, etc.

    msdn.microsoft.com/.../aa846236.aspx

    You could use the Global class for getting the null value as a proxy class/business connector call  from AX.

    msdn.microsoft.com/.../global.nullvalue.aspx

  • psined Profile Picture
    on at

    Hi, thanks for quick response.

    I fully understand that AX built-in string type cannot take a null value rather than an empty string. The behavior I need though is to pass DBNull.Value object to one of the required System.Data.SqlClient.SqlParameter instance whenever the source X++ string is empty. The SQL parameter is required, so I must pass it a value, it's just at times the value needs to be DBNull.Value. This can be easily achieved and is a normal practice in C#.

    Not sure I understand how I could use Global::nullValue(<type>), nor ClrInterop::Null(<type>) here. DBNull.Value is not the same as Global::nullValue("System.DBNull") if that is what you mean.

  • Vilmos Kintera Profile Picture
    46,149 on at

    Am I understanding right that you use reflection to use the .Net SQL namespaces to write code inside AX?

    Maybe you could just write the whole logic in a C# project as a wrapper which could handle your DBNull value correctly, do the calculations or whatever you would like to use there, and pass the end result back to AX for further processing.

  • psined Profile Picture
    on at

    Thanks Vilmos.

    Well, I guess it kinda fits between AX and .Net. I'm making calls to CLR objects from within X++ so this obviously circles into the CLR interop topic. It seems that marshaling in CLR interop for AX R3 is a little quirky - my other thread on the System.Double type interop from X++ code adds to that.

    I'll wait for other opinions. Meantime I'll think of a workaround on the SQL side of things, such as NULLIF() function and such...

    Thanks for your help again!

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    It seems that .NET Interop from X++ doesn't support static properties.

    Consider creating a C# project in AOT and write most code using .NET types in C#, which will help you to avoid all such issues and allow you to use all C# features. I tend to use it for every time when I need more than just a few lines of code with .NET types.

    Things like nullValue() aren't going to help, because what Value returns is an object instance, not a null reference or a default value in any way.

  • psined Profile Picture
    on at

    OK, that's what I thought. Thanks Martin.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans