bang head here Posted February 3, 2003 Posted February 3, 2003 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. Quote
Moderators Robby Posted February 3, 2003 Moderators Posted February 3, 2003 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) Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.