»
S
I
D
E
B
A
R
«
Conversion from type ‘DBNull’ to type ‘String’ is not valid
June 1st, 2009 by webpaws

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

VN:F [1.8.5_1061]
Rating: 6.8/10 (4 votes cast)
VN:F [1.8.5_1061]
Rating: -1 (from 1 vote)
Conversion from type 'DBNull' to type 'String' is not valid6.8104
 
Take a piece of the Web from WebPaws.com: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • MisterWong
  • Y!GG
  • Webnews
  • Digg
  • del.icio.us
  • StumbleUpon
  • De.lirio.us
  • eKudos
  • email
  • Facebook
  • Fleck
  • Google Bookmarks
  • Hype
  • LinkedIn
  • MySpace
  • Print
  • Technorati
  • YahooMyWeb

3 Responses  
  • AndrewBoldman writes:
    June 4th, 2009 at 8:43 pm

    Hi, cool post. I have been wondering about this topic,so thanks for writing.

    UN:F [1.8.5_1061]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.5_1061]
    Rating: 0 (from 0 votes)
  • feliciafet writes:
    June 6th, 2009 at 5:35 am

    In it something is. Now all became clear, many thanks for the help in this question.

    UN:F [1.8.5_1061]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.5_1061]
    Rating: 0 (from 0 votes)
  • shanwaj writes:
    June 25th, 2009 at 8:58 am

    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

    UN:F [1.8.5_1061]
    Rating: 5.0/5 (1 vote cast)
    UN:F [1.8.5_1061]
    Rating: 0 (from 0 votes)

Leave a Reply

»  Substance: WordPress   »  Style: Ahren Ahimsa
© Copyright by WebPaws.com 2009. All Rights Reserved.

WebPaws.com is Digg proof thanks to caching by WP Super Cache