NULL value

  • Thread starter Thread starter simon
  • Start date Start date
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
 
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
 
Better check if the object is null first in your procedure and if it is, then
return empty string
 
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
 
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
 
Back
Top