"Type 'DataSetName' is not defined" error message when you build the project


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.


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.


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
  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.


This behavior is by design.

More Information

Steps to Reproduce the Behavior

  1. In Microsoft Visual Studio .NET, create a new Visual C# Windows Application project. By default, Form1 is created.
  2. On the View menu, click Server Explorer.
  3. In Server Explorer, right-click Data Connections, and then click Add Connection.
  4. In the Data Link Properties dialog box, on the Connection tab, type your local SQL Server name, and then select the Northwind database.
  5. On the Data tab of the Toolbox, drag a
    SqlConnection to Form1.
  6. Right-click SqlConnection1, and then click
    Properties. In the Properties dialog box, set
    ConnectionString to the data connection that you created in step 4.
  7. Drag a SqlDataAdapter from the Toolbox to Form1. In the Data Adapter Configuration Wizard, click Nextthree times, and then type the following SQL statement:
    Select * From Customers
  8. Click Next, and then click
    Finish to close the wizard.
  9. Right-click SqlDataAdapter1, and then click Generate Dataset. Click OK.
  10. On the View menu, click Solution Explorer.
  11. In Solution Explorer, double-click
  12. On the View menu, click Properties Window.
  13. In the Properties pane, select
    DataSetName, and then change the name to
  14. Save the project, and then in Solution Explorer, double-click Form1.cs.
  15. On the Build menu, click Build Solution.


For more information, visit the following Microsoft Developer Network (MSDN) Web sites:BUG #: 3347 (Content Maintenance)

ID do Artigo: 816801 - Última Revisão: 23 de mar de 2009 - Revisão: 1