Urgent: DBNull error - 'System.InvalidCastException'
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Urgent: DBNull error - 'System.InvalidCastException'

  1. #1
    Join Date
    Nov 2013
    Posts
    7

    Urgent: DBNull error - 'System.InvalidCastException'

    Using Visual Studio 2008 and generating .net 2.0 framework with VB.net for a web application.

    I encountered a very strange problem currently. After I build a solution and click a link in a web page, I got an error message as following. The same thing happened when I tried to run in debug mode.

    *************************************** ERROR Message ******************************************************
    "An exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll but was not handled in user code"
    "Additional information: Operator '=' is not defined for type 'DBNull' and string "". "
    *******************************************************************************************************************

    The problem part is simply as below in a vb file. The value of dataview(0)(“name”) is NULL and my_name is a variable string. The strange is thing I didn’t change any code in this vb file. This vb file was built previously and used for a long time ago without any problem. It just suddenly happened today. I have this syntax all over the program without causing any problem. I have tried to restore the whole solution back to original but still have the problem.
    Can anyone please advise why all the sudden and how to fix? Thanks.

    “If dataview(0)(“name”) = my_name then …”

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Urgent: DBNull error - 'System.InvalidCastException'

    one of the records (or more) does not have data entered for the column "name" and thus returns a DBNull..either repair the data, or handle the DBnull..

    btw you will need to use if Var IS DBNull then
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Nov 2013
    Posts
    7

    Re: Urgent: DBNull error - 'System.InvalidCastException'

    Thanks for your advice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center