Answered by:
Handling DBNull in an ImageURL

Question
-
User1210767569 posted
I have a hyperlink, as below, that works unless there is a blank in FS2. This error related to the "DateToSymbol" function. I have tried several things from looking for blanks to DBNull.
Error: Compiler Error Message: BC30108: 'DBNull' is a type and cannot be used as an expression.
Code:
<asp:HyperLink ID="FS2" runat="server" NavigateUrl='<%# Page.Request.Path + "?reqid=" + Eval("PId") + "&TypeID=FS2" %>' imageurl='<%# DateToSymbol(Eval("FS2"))%>'> </asp:HyperLink>
Code behind:Public Function DateToSymbol(ByVal vDateTidy As Date) As String If DBNull(vDateTidy) = True Then 'skip Else Dim vString As String If vDateTidy <= DateTime.Now Then vString = "../../images/add_button.png" Else vString = "../../images/add_button1.png" End If End If End If Return vString End Function
Tuesday, April 22, 2014 6:27 AM
Answers
-
User-718146471 posted
I think the syntax should actually be:
http://msdn.microsoft.com/en-us/library/system.dbnull.value(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2 If Not DbNull.Value.Equals(row.Item(fieldName)) Then Return CStr(row.Item(fieldName)) & " " Else Return Nothing End If
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 22, 2014 6:45 AM
All replies
-
User-718146471 posted
I think the syntax should actually be:
http://msdn.microsoft.com/en-us/library/system.dbnull.value(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2 If Not DbNull.Value.Equals(row.Item(fieldName)) Then Return CStr(row.Item(fieldName)) & " " Else Return Nothing End If
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 22, 2014 6:45 AM -
User-718146471 posted
Keep in mind this is a direct example, you may want to use the field you specified in the DbNull.Value.Equals(yourvalue)
Tuesday, April 22, 2014 6:46 AM -
User-1716253493 posted
If IsDBNull(vDateTidy) ThenTuesday, April 22, 2014 6:56 AM -
User1210767569 posted
Looking good. My final code is:
Public Function DateToSymbol(ByVal vDateTidy) As String If Not DBNull.Value.Equals(vDateTidy) Then Dim vString As String If vDateTidy <= DateTime.Now Then vString = "../../images/add_button.png" Else vString = "../../images/add_button1.png" End If Return vString Else Return Nothing End If End Function
Tuesday, April 22, 2014 7:06 AM