Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Conversion from type 'DBNull' to type 'String' is not valid

Reply
Thread Tools

Conversion from type 'DBNull' to type 'String' is not valid

 
 
Cirene
Guest
Posts: n/a
 
      06-18-2008
I'm setting a databound label's backcolor and forecolor like this...

<asp:Label ID="lblSampleColorScheme" runat="server"

BackColor='<%#
System.Drawing.Color.FromName(Eval("AttachmentEnti tyBackColor")) %>'
Font-Bold="True"

ForeColor='<%#
System.Drawing.Color.FromName(Eval("AttachmentEnti tyForeColor")) %>'
Text="CURRENT COLOR SCHEME"></asp:Label>


The problem is when the value is NULL. I get the above error. How can I
say, if it's null in the db then use "#ffffff"?

Thanks!


 
Reply With Quote
 
 
 
 
Cirene
Guest
Posts: n/a
 
      06-18-2008
This doesn't seem to work...

<asp:Label ID="lblSampleColorScheme" runat="server"

BackColor='<%# iif(eval("AttachmentEntityBackColor").equals(DBNul l.value),
"#ffffff", System.Drawing.Color.FromName(Eval("AttachmentEnti tyBackColor")))
%>' Font-Bold="True"

ForeColor='<%# iif(eval("AttachmentEntityForeColor").equals(DBNul l.value),
"#000000", System.Drawing.Color.FromName(Eval("AttachmentEnti tyForeColor")))
%>' Text="CURRENT COLOR SCHEME"></asp:Label>


"Cirene" <> wrote in message
news:...
> I'm setting a databound label's backcolor and forecolor like this...
>
> <asp:Label ID="lblSampleColorScheme" runat="server"
>
> BackColor='<%#
> System.Drawing.Color.FromName(Eval("AttachmentEnti tyBackColor")) %>'
> Font-Bold="True"
>
> ForeColor='<%#
> System.Drawing.Color.FromName(Eval("AttachmentEnti tyForeColor")) %>'
> Text="CURRENT COLOR SCHEME"></asp:Label>
>
>
> The problem is when the value is NULL. I get the above error. How can I
> say, if it's null in the db then use "#ffffff"?
>
> Thanks!
>



 
Reply With Quote
 
 
 
 
nick chan
Guest
Posts: n/a
 
      06-19-2008
u can't use IIF()
System.Drawing.Color.FromName(Eval("AttachmentEnti tyForeColor")) will
still be executed, resulting in error

(IIF is not equaivalent to C's '?' command)

u need to write another function

public function BackColor(AColor as Object) as String
if typeof AColor is DBNull then
return "#FFFFFF"
else
return System.Drawing.Color.FromName(AColor)
end if
end function

BackColor='<%#BackColor(eval("AttachmentEntityBack Color"))%>'

On Jun 19, 5:33*am, "Cirene" <cir...@nowhere.com> wrote:
> This doesn't seem to work...
>
> <asp:Label ID="lblSampleColorScheme" runat="server"
>
> BackColor='<%# iif(eval("AttachmentEntityBackColor").equals(DBNul l.value),
> "#ffffff", System.Drawing.Color.FromName(Eval("AttachmentEnti tyBackColor")))
> %>' Font-Bold="True"
>
> ForeColor='<%# iif(eval("AttachmentEntityForeColor").equals(DBNul l.value),
> "#000000", System.Drawing.Color.FromName(Eval("AttachmentEnti tyForeColor")))
> %>' Text="CURRENT COLOR SCHEME"></asp:Label>
>
> "Cirene" <cir...@nowhere.com> wrote in message
>
> news:...
>
> > I'm setting a databound label's backcolor and forecolor like this...

>
> > <asp:Label ID="lblSampleColorScheme" runat="server"

>
> > BackColor='<%#
> > System.Drawing.Color.FromName(Eval("AttachmentEnti tyBackColor")) %>'
> > Font-Bold="True"

>
> > ForeColor='<%#
> > System.Drawing.Color.FromName(Eval("AttachmentEnti tyForeColor")) %>'
> > Text="CURRENT COLOR SCHEME"></asp:Label>

>
> > The problem is when the value is NULL. *I get the above error. *How can I
> > say, if it's null in the db then use "#ffffff"?

>
> > Thanks!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion from type 'DBNull' to type 'String' is not valid.,asp.net&vb jerryantony Software 0 11-04-2009 08:00 AM
Conversion from string to type double is not valid Ed Dror ASP .Net 2 04-08-2008 06:36 PM
Conversion from type 'DBNull' to type 'String' is not valid Chris ASP .Net 2 05-11-2006 08:20 AM
conversion from type 'DBNull' to type 'float' is not valid ibiza ASP .Net 2 01-27-2006 09:57 PM
Cast from type 'DBNull' to type 'String' is not valid. Elmo Watson ASP .Net 3 12-25-2003 03:30 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57