Article ID: 310371 - View products that this article applies to.
This article was previously published under Q310371
This article refers to the following Microsoft .NET Framework Class Library namespaces:
When you reference the value of a DataColumn that is NULL, whether typed or untyped, you receive an exception.
For typed DataSets, you receive the following exception:
For untyped DataSets, you receive the following exception:
An unhandled exception of type 'System.Data.StrongTypingException' occurred in invalidcast.exe
Additional information: Cannot get value because it is DBNULL.
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from type 'DBNULL' to type 'String' is not valid.
Cause 1When you use a typed DataSet, the exception is caused when you reference the column value that is NULL.
Cause 2When you use an untyped DataSet, the value of the column is NULL, and the variable to which you assign it does not support NULL.
Cause 1Test the column for NULL before you access its value. In an untyped DataSet, use the DataRow.IsNull method. In a typed DataSet, use the DataRow.IscolumnnameNull property.
Cause 2Use a variable of an appropriate data type that can store NULL.
Steps to reproduce the behavior
For more information about creating a typed DataSet, click the following article number to view the article in the Microsoft Knowledge Base:
315678For more information about ADO.NET, click the following article number to view the article in the Microsoft Knowledge Base:
(https://support.microsoft.com/kb/315678/ )How to create, use typed DataSet by using Visual Basic .NET
(https://support.microsoft.com/kb/313590/ )Roadmap for ADO.NET
Article ID: 310371 - Last Review: February 27, 2007 - Revision: 2.7