🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.csharpbuilder.aspdotnet.general
2 messages
2 total messages Started by Ramtin Fri, 15 Apr 2005 21:48
Databinding to a property and SQL NULL value ?
#41
Author: Ramtin
Date: Fri, 15 Apr 2005 21:48
15 lines
1314 bytes
Hi
 suppose this binding :

<asp:Label runat="server" Text='<%# MyFunction( (DateTime)
DataBinder.Eval(Container,"DataItem.ExpireDate")) %>'
ID="Label1"></asp:Label>

which MyFunction is a function with a DateTime parameter and string result.
The problem is here: the field ExpireDate can have SQL NULL value and this
with throw an exception because of invalid type casting (NULL to DateTime).

What should I do to avoid this exception?

Thanks
Ramtin K.
Re: Databinding to a property and SQL NULL value ?
#44
Author: bm
Date: Wed, 29 Jun 2005 10:59
43 lines
2328 bytes
The casting should not cause a problem only when you operate.on it in your 
function as DateTime you may have problems. Failing that you could always do 
a check for null first and pass onto function if it isn't or return a blank 
string.

If the casting a NULL is a problem then
 <asp:Label runat="server"
   Text='<%# DataBinder.Eval(Container,"DataItem.ExpireDate") != null
                    ?  MyFunction( (DateTime) 
DataBinder.Eval(Container,"DataItem.ExpireDate"))
                    :   ""
               %>'
   ID="Label1"></asp:Label>


> DataBinder.Eval(Container,"DataItem.ExpireDate")) %>'


Text='<%# MyFunction( (DateTime) 
DataBinder.Eval(Container,"DataItem.ExpireDate")) %>'

"Ramtin" <Raka1381@yahoo.com> wrote in message 
news:426036cb@newsgroups.borland.com...
> Hi
> suppose this binding :
>
> <asp:Label runat="server" Text='<%# MyFunction( (DateTime)
> DataBinder.Eval(Container,"DataItem.ExpireDate")) %>'
> ID="Label1"></asp:Label>
>
> which MyFunction is a function with a DateTime parameter and string 
> result.
> The problem is here: the field ExpireDate can have SQL NULL value and this
> with throw an exception because of invalid type casting (NULL to 
> DateTime).
>
> What should I do to avoid this exception?
>
> Thanks
> Ramtin K.
>
>
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads