Monday, January 11, 2010

Server Error:Operator '<>' is not defined for type 'DBNull' and type 'Integer'.

Some time I see the Server Error message in our SilverNet web based inventory system
I've investigated this problem and found that in the row:

<asp:Label ID="Label3" runat="server" Text='<%# Eval("Paid", "{0:N}") %>' Visible='<%# Eval("Paid")<>0 %>' ></asp:Label>
The field "Paid" can be DbNull.
First, I tried to check the value Paid before using it in the Eval function. But then,I've found very simple solution. I've edited SQL query in the data source. I've changed the "Select Paid ..." on "Select IsNull(Paid,0) As Paid...."
DbNull is an insidious thing!

No comments:

Post a Comment