The legal tricks-Learn Your Self

Latest gadgets,softwares,hardware,reviews,programming and campuses, game cheats ext......

Handle Database Null Values in VB.NET/ASP.NET

Version Compatibility: Visual Basic.NET, ASP.NET

More information: Handling null values returned from database resultsets is different in .NET from VB6, and the documentation is not that clear on how to do it. The first of these functions returns true if such a value is null, the second converts the value to an empty string if it is null.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Public Function IsDBNull(ByVal dbvalue) As Boolean
Return dbvalue Is DBNull.Value
End Function

Public Function FixNull(ByVal dbvalue) As String
If dbvalue Is DBNull.Value Then
Return ""
Else
'NOTE: This will cast value to string if
'it isn't a string.

Return dbvalue.ToString
End If
End Function

0 comments: