Microsoft KB Archive/816801

= &quot;Type 'DataSetName' is not defined&quot; error message when you build the project =

Article ID: 816801

Article Last Modified on 5/12/2007

-

APPLIES TO


 * Microsoft ADO.NET 2.0
 * Microsoft ADO.NET 1.1
 * Microsoft ADO.NET 1.0
 * Microsoft Visual C# 2005 Express Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



SYMPTOMS
When you create a DataSet during design time by using the Generate DataSet option of a DataAdapter, an instance of the DataSet is automatically created on the form. When you modify the name of the DataSet in the Properties window, save the project, and then try to open the form, you may receive the following error message on the form:

An error occurred while loading the document. Fix the error, and then try loading the document again. The error message follows:

Unspecified error

When you build your project, you may receive the following error message:

Type 'ApplicationName.OldDataSetName' is not defined.



CAUSE
The problem occurs because when the DataSet name is changed in the DataSet schema file (.xsd), Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET does not modify the DataSet name in the InitializeComponent of the form where the DataSet is initialized.



RESOLUTION
To resolve this problem, replace the DataSet name with the new name in the code. To do this, follow these steps:
 * 1) On the View menu, click Code.
 * 2) In the code, replace each instance of the Dataset name from DataSet1 to MyDataSet.
 * 3) Save the project, and then in Solution Explorer, double-click Form1.cs.



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
 In Microsoft Visual Studio .NET, create a new Visual C# Windows Application project. By default, Form1 is created. On the View menu, click Server Explorer. In Server Explorer, right-click Data Connections, and then click Add Connection. In the Data Link Properties dialog box, on the Connection tab, type your local SQL Server name, and then select the Northwind database. On the Data tab of the Toolbox, drag a SqlConnection to Form1. Right-click SqlConnection1, and then click Properties. In the Properties dialog box, set ConnectionString to the data connection that you created in step 4.</li>  Drag a SqlDataAdapter from the Toolbox to Form1. In the Data Adapter Configuration Wizard, click Next three times, and then type the following SQL statement: Select * From Customers </li> Click Next, and then click Finish to close the wizard.</li> Right-click SqlDataAdapter1, and then click Generate Dataset. Click OK.</li> On the View menu, click Solution Explorer.</li> In Solution Explorer, double-click DataSet1.xsd.</li> On the View menu, click Properties Window.</li> In the Properties pane, select DataSetName, and then change the name to MyDataSet .</li> Save the project, and then in Solution Explorer, double-click Form1.cs.</li> On the Build menu, click Build Solution.</li></ol>

<div class="references_section">