[RESOLVED]how to handle {} result from QueryValue that returns a decimal

The query below returns a decimal.

When I hover over unpaid Visual Studio says unpaid {}, not unpaid null what I was expecting.

How do I catch this so that I can assign a 0 value in this case?

var unpaid = db.QueryValue(sqlSelect5, providerid, item.ownerLocationId, false);

Hi wavemaster,

The DBNull.Value represents the sole instance of the DBNull class.

There is a link about DBNull class that may benefit you:

# DBNull Class

http://msdn.microsoft.com/en-us/library/system.dbnull(v=vs.110).aspx

Best Regards

Starain Chen

No clue what that all means, including what is at the msdn link.

Typically a query returning no results can be protected against that with a simple results == null check.

When the query result is a decimal this no longer works. Now I need a contraption like this:
if ((object)unpaid
!= System.DBNull.Value)

It works, but it makes absolutely no sense to me as to why this needs a different approach.

wavemaster

Now I need a contraption like this: if
((
object)unpaid
!= System.DBNull.Value)

If you are querying a column that allows null values, the return from the query could be a database NULL, which is represented in .NET as DBNull.Value. This is different to a C# null. It means that a row and column matched your criteria, but the value of
the cell was NULL. If no records match at all, the result of your QueryValue call when represented in C# will be null.

that was helpful in understanding this.

thnx

Leave a Reply