🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.aspdotnet.general
Article #44

Re: Databinding to a property and SQL NULL value ?

#44
From: 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.
>
>
> 
Technical Details
Message-ID: <42c27edb@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!newsread.com!newsprint.newsread.com!63.218.45.11.MISMATCH!newshosting.com!nx02.iad01.newshosting.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <426036cb@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 124d48,2f0c616baeb7aa42
X-Google-Attributes: gid124d48,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "bm" <bm@nospam.com>
Newsgroups: borland.public.csharpbuilder.aspdotnet.general
References: <426036cb@newsgroups.borland.com>
Subject: Re: Databinding to a property and SQL NULL value ?
Date: Wed, 29 Jun 2005 11:59:51 +0100
Lines: 45
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 80.1.192.74
Message-ID: <42c27edb@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1120042715 80.1.192.74 (29 Jun 2005 03:58:35 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!newsread.com!newsprint.newsread.com!63.218.45.11.MISMATCH!newshosting.com!nx02.iad01.newshosting.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail