Connecting Tech Pros Worldwide Forums | Help | Site Map

Null parameter problem

E. Kwong
Guest
 
Posts: n/a
#1: Sep 10 '08
I have a function that takes two arguments



Public Function CheckThing(ByVal b As Boolean, ByVal s as String) As
String

:

The function is called from inside a FormView control like this:



<%#CheckThing(Eval("flag"),Eval("myfield"))%>



Everything works fine except when myfield has a null value: I'll then get
an error saying something like ".can not convert DBNull to string.."



What's the best way to handle situation like this? Thanks.



I'm using VS2005, and SQL Server database.





breitak67
Guest
 
Posts: n/a
#2: Sep 11 '08

re: Null parameter problem



There area number of ways. First, if you are okay with deciding there
should be no nulls in this field from the db, modify the sproc that
returns the data to replace myfield with ISNULL(myfield,'') in the T-SQL
select statement.

There are ways to handle it in the app code as well. I have been using
C#.NET since 2003, so I will have to pull up VS and figure out the
equivalent VB.NET syntax. I'll post back later with that.


--
breitak67
breitak67
Guest
 
Posts: n/a
#3: Sep 11 '08

re: Null parameter problem



Replace myfield with:

IIf(Eval(\"myfield\") Is System.DBNull.Value, \"\", Eval(\"myfield\"))

You can also change the parameter type to allow a DBNull to come across
and handle it in the CheckThing function.


--
breitak67
Closed Thread