Error message when you use CommandBuilder: "An unhandled exception of type 'System.NullReferenceException' occurred" (310367)
The information in this article applies to:
- Microsoft ADO.Net 2.0
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2002)
- Microsoft Visual J# .NET (2002)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic 2005
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# 2005
- Microsoft Visual J# .NET (2003)
This article was previously published under Q310367 This article refers to the following Microsoft .NET
Framework Class Library namespaces:
- System.Data.OleDb
- System.Data.SqlClient
SYMPTOMS If you use the CommandBuilder object to explicitly get commands for the DataAdapter object as follows:
da.InsertCommand = cb.GetInsertCommand
and then run the following Visual Basic .NET code
cb.DataAdapter = Nothing
or the following Visual C# .NET code
cb.DataAdapter = null;
the commands that you add to the DataAdapter are deleted, and you receive the following error message:
An unhandled exception of type
'System.NullReferenceException' occurred in
app_name.exe
Additional information:
Object reference not set to an instance of an object. CAUSECommandBuilder deletes the commands that it generates when it is disassociated
from a DataAdapter. CommandBuilder and DataAdapter are linked; when they are unlinked or disassociated, the commands
are nulled. This problem does not affect commands that you build from the
beginning (from scratch). RESOLUTION Use one of the following methods to resolve this problem:
- Do not disassociate the CommandBuilder from the DataSet.
- Build the commands yourself, either in code or through
Visual Data Tools.
STATUSThis
behavior is by design.
Modification Type: | Minor | Last Reviewed: | 10/4/2006 |
---|
Keywords: | kbtshoot kberrmsg kbprb kbSqlClient kbSystemData KB310367 kbAudDeveloper |
---|
|