In a VB.net application, retrieving variables from a database, if the value was null, it would cause the error, “Conversion from type ‘DBNull’ to type ‘String’ is not valid”. A work-around to stop this error was to create a function that would evaluate the imported database variable for a null value as an object then convert it to a string for use without error in your code.
Here is the VB.net code:
Function checkNull(Byval variable as object) as String If IsDBNull(varialbe) Then Return("") Else Return (variable) End If End Function
Hi, cool post. I have been wondering about this topic,so thanks for writing.
In it something is. Now all became clear, many thanks for the help in this question.
Hi there, Very nice example,i am struggling to convert dbnull to string.Every time i am getting error.I solved my problem with your example.
Thanks a lot
Name (required)
Mail (will not be published) (required)
Website
WebPaws.com is Digg proof thanks to caching by WP Super Cache