VB2005 Database Null Exceptions

Posted on 2007-07-20
Last Modified: 2012-08-14
Hi - my program is crashing when it reaches this code:

If IsNothing(Formula.Comments) Then
            txtOut.Text += "There are no formula specific notes."
            txtOut.Text += Formula.Comments
        End If

Formula.Comments is a field in an Access Database and the IsNothing line is where it dies.  It crashes to (myform).designer,vb at line:

  Throw New System.Data.StrongTypingException("The value for column 'Comments' in table 'tblFormulas' is DBNull.", e)

StrongTypingException was unhandled.

I thought the IsNothing function prevented this error?  I want to test for a null and do something about it - not crash  :)

Question by:jakyll
    LVL 33

    Expert Comment

    try this

    If Formula.Comments.Equals(System.DBNull.Value) Then
    LVL 96

    Accepted Solution

    If you have a typed dataset, then read this:

    HOW TO: Make a Typed DataSet Return a Default Value Instead of DBNull by Using Visual Basic .NET


    Author Comment

    hongjun:  Thanks but unfortunately that didn't work

    TheLearnedOne:  I think this is the right answer - but I cannot figure out where to put:  <xs:element name="Region" codegen:nullValue="-1" type="xs:string"  minOccurs="0" />   I have no element named "region" in my dataset??

    LVL 96

    Expert Comment

    by:Bob Learned
    The Northwind database Customers table has the Region column.  You need to find the column name that you are having problems with.


    Author Comment

    Oh nevermind I see - thank you very much!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now