NULL value

S

simon

I have item template:

<ItemTemplate>
<%#
writeProcent(DataBinder.Eval(Container.DataItem,"strosekProcentBrez")) %>
</ItemTemplate>

and function in code behind:

Protected Function writeProcent(ByVal vrednost As Decimal) As String
If vrednost = 100 Then
writeProcent = "<font color=red>-</font>"
Else
writeProcent = vrednost
End If
End Function

when I execute the page,I get an error message:

cast from type 'DBNull' to type 'Decimal' is not valid

How can I check if DataBinder.Eval is not null?

Thank you,
Simon
 
H

Hans Kesting

simon said:
I have item template:

<ItemTemplate>
<%#
writeProcent(DataBinder.Eval(Container.DataItem,"strosekProcentBrez"))
%> </ItemTemplate>

and function in code behind:

Protected Function writeProcent(ByVal vrednost As Decimal) As String
If vrednost = 100 Then
writeProcent = "<font color=red>-</font>"
Else
writeProcent = vrednost
End If
End Function

when I execute the page,I get an error message:

cast from type 'DBNull' to type 'Decimal' is not valid

How can I check if DataBinder.Eval is not null?

Thank you,
Simon

You could change the function to accept an *object* instead of a decimal.
Then you can do your typecheck inside the function.

Hans Kesting
 
G

Guest

Better check if the object is null first in your procedure and if it is, then
return empty string
 
S

simon

Hi,

thank you for your answer.
But is this really necessary?
Declaring the variable as object takes a lot of space.

I have function with 12 parameters, so all must be declared as object,
because almost all can be null?
What is than the sence of declaring, like decimal, string, integer....?

hank you,
Simon
 
J

John Saunders

simon said:
Hi,

thank you for your answer.
But is this really necessary?
Declaring the variable as object takes a lot of space.

I have function with 12 parameters, so all must be declared as object,
because almost all can be null?

All 12 parameters come from a database? Do all 12 come from columns which
permit NULL?
What is than the sence of declaring, like decimal, string, integer....?

So that you don't try to add strings, or assign 1.5 to an integer.

John Saunders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top