More stupid bits of code
Posted: 9/15/2005 9:08:59 AMBy: Comfortably Anonymous
Times Read: 1,568
Likes: 0 Dislikes: 0
Topic: Programming: .NET Framework
Here's another example of trying to re-invent the wheel (The NullToString function, not the IsDBNull function, or at least I don't think so anyway :) ). Post your redundant code here too, so that we can all learn from our mistakes
Protected Function IsDBNull(ByVal DBVal) As Boolean
' Checks if value passed from Database is Null
' Returns True if passed value is Null
' Returns False is passed value is Not Null
Return DBVal Is DBNull.Value
End Function
Protected Function NullToString(ByVal DBVal) As String
' Returns empty string is value passed from database is Null
' Converts value to a string if Not Null
' *************************************************************************************
' ** Turns out that if you just use the .ToString method of returned values, it will **
' ** do the same thing automatically. So consider this function deprecated. **
' *************************************************************************************
If IsDBNull(DBVal) Then
Return ""
Else
Return DBVal.ToString
End If
End Function
Protected Function IsDBNull(ByVal DBVal) As Boolean
' Checks if value passed from Database is Null
' Returns True if passed value is Null
' Returns False is passed value is Not Null
Return DBVal Is DBNull.Value
End Function
Protected Function NullToString(ByVal DBVal) As String
' Returns empty string is value passed from database is Null
' Converts value to a string if Not Null
' *************************************************************************************
' ** Turns out that if you just use the .ToString method of returned values, it will **
' ** do the same thing automatically. So consider this function deprecated. **
' *************************************************************************************
If IsDBNull(DBVal) Then
Return ""
Else
Return DBVal.ToString
End If
End Function
Rating: (You must be logged in to vote)