View Single Post
  #121 (permalink)  
Old 09-25-2007, 08:52 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: ASP.NET Data Controls

hi guys,

I am using Visual Studio 2005 and ASP.NET 2.0 and SQL Server Express 2005
Ok I've come up with the next problem:

I want to check if a field has a value and if it has it should display it, otherwise it shoudn't. Now In my database I've got fields wich have the Nulls allowed properties.These fields will have the initial value of NULL and when I erase the NULL value it will have no value.
So Im using the next statements to check this:

<%#IIf(IsDBNull(DataBinder.Eval(Container.DataItem , "Adreslijn2")) , "" , DataBinder.Eval(Container.DataItem, "Adreslijn2") & "<BR />")%>
This will work if the field has the initial NULL value but if it has no value or a value, both ways it will give no error but it will still print the breakline even if it has an empty value because it is not NULL ofcourse while it also shouldn't print the breakline if it has an empty value.

<%#IIf(DataBinder.Eval(Container.DataItem, "Adreslijn2") = ""), "" , DataBinder.Eval(Container.DataItem, "Adreslijn2") & "<BR />")%>
This will work if the field has no value (so when I have erased the initial NULL value) but when the field still has the initial NULL value it will give the following error:
Operator '=' is not defined for type 'DBNull' and string "".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Operator '=' is not defined for type 'DBNull' and string "".
Using OR in the IIF line of course also does not work because it will still give the error when the field contains the NULL value
Does anyone here know a solution for this? Is it maybe possible to give my fields in my database an initial empty value instead of NULL so when a new record is created it will fill the empty records with no value instead of NULL or is there another solution to this?


Thanks in advance
__________________
Venkat
knowledge is Power
Reply With Quote
Sponsored Links