Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Pretty easy, I'm reading in a table that has some Null values scattered about. In binding the data to the grid I have an error because of the Nulls, cannot Cast Null value into a String. Yeah well that makes sense. But how can I call a function to check for the Null value and then populate the cell with " "?

 

<asp:Label ID="lblDateOut" Text='<%# TrimNull(Mid(DataBinder.Eval(Container.DataItem, "Date Out"),1,10)) %>' Runat="server" EnableViewState="false" />

&

      Public Function TrimNull(ByVal sInput As String)
           If (sInput is System.DBNull.Value) Then
               TrimNull = " "
               return TrimNull
           Else
               TrimNull = sInput
               return TrimNull
           End If
       End Function

The above won't work because the Parameter for TrimNull is Null so I get the same error right? How can I do a logic check like this for DBNulls?

 

Many thanks.

  • Moderators
Posted

you can use this function...

   Protected Function Nz(ByVal vValue As Object, ByVal vDefValue As Object) As Object
       If IsDBNull(vValue) Then
           Return vDefValue
       Else
           If vValue Is Nothing Then
               Return vDefValue
           Else
               Return vValue
           End If
       End If
   End Function

'and call it this way

CType(Nz(drSqlReader.Item("SomeStringField"), ""), String)

'or
CType(Nz(drSqlReader.Item("SomeNumericField"), ""), Integer)

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...