Null values

Stimulsoft Reports.NET discussion
Post Reply
ikirck
Posts: 23
Joined: Fri Aug 25, 2006 4:25 am

Null values

Post by ikirck »

Hi,

for several reports, I need to discern if a given field equals null or 0.

I have the ConvertNulls-property of the report set to false.

In the Databand.Beforeprint event, I have tried this

if (!Datenquelle1.STMAPROZENT.Equals(null))

and this

if (Datenquelle1.STMAPROZENT != null)

Both versions compile all rigth, but I get the following error at runtime:

Method: [get_STMAPROZENT]
Die angegebene Umwandlung ist ungültig.

this should roughly translate to: this conversion is invalid.

So, what am I doing wrong?

Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Null values

Post by Edward »

Please use the following expression for checking for the null values (in the onGetValue event handler for example):

Code: Select all

if (Datenquelle1["STMAPROZENT"] == null)e.Value = "YES";
	else e.Value = "NO";
ConvertNulls property should be set to false.

Thank you.

ikirck
Posts: 23
Joined: Fri Aug 25, 2006 4:25 am

Null values

Post by ikirck »

Ok, I tried this, and now I have the following code in Databand1.BeforePrint:

Code: Select all

double wgt;

if (Datenquelle1["STMAPROZENT"] == null)
{
    MessageBox.Show("null");
    wgt = 1;
}
else
{
    MessageBox.Show("not null");
    wgt = Datenquelle1.STMAPROZENT/100;
}
If I edit my SQL-Statement to include only datarows where STMAPROZENT is not null, this works all right. If I only include datarows where STMAPROZENT is null, it still always goes into the else branch. Then, the line

Code: Select all

wgt = Datenquelle1.STMAPROZENT/100;
results in the error message that I have posted before.
So it seems that null values are not recognized as such.

Am I still doing something wrong? Do I have to use another event for this?
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Null values

Post by Vital »

Please check following code:

Code: Select all

if (Datenquelle1["STMAPROZENT"] == null || Datenquelle1["STMAPROZENT"] == DBNull.Value))
Thank you.
ikirck
Posts: 23
Joined: Fri Aug 25, 2006 4:25 am

Null values

Post by ikirck »

All right, it works now.

Thanks a lot, great service!
Post Reply