Home   |   Asp.Net 2.0   |   .Net Framework 2.0   |   IIS 6.0   |   Sql Server 2005   |   Visual Basic 2005   |   c# 2005   |   VS 2005   |   Visual Source Safe 2005

MS Dynamics CRM 3.0

SharePoint Portal Server 2003
SharePoint Server 2007
Dynamics NAV
Dynamics CRM
SharePoint Designer 2007
SharePoint Portal Server 2001
Windows SharePoint Services
Windows SharePoint Services 3.0
Project Server 2003
Project Server 2007
Dynamics – Point of Sale
Dynamics AX
Dynamics GP
Dynamics Retail Management System (RMS)
Dynamics SL
SQL Server 2000
Visual Basic .NET 2003
Visual C# .NET 2003
Visual C++ .NET 2003
Visual C++ 2005
Visual SourceSafe 6.0
Windows Server 2003
Windows Server 2003
Outlook 2003
ADO.NET 1.1
ASP.NET 1.0
Visual Studio Team Foundation Server
Visual Studio 2005 Team Edition
Windows Internet Explorer 7
BizTalk Server 2000
BizTalk Server 2002
BizTalk Server 2004
BizTalk Server 2006
Visual Studio 6.0
Access 2000
Access 2002
Access 2003
Access 2007
Access 97
Collaboration Data Objects 2.0
Commerce Server 2002
Content Management Server 2001
Commerce Server 2007
Content Management Server 2002
Data Access Components 2.7
Data Access Components 2.8
DirectX 9.0b
Office Small Business Accounting 2006
Accounting 2007
ActiveSync 4.1
Class Server 2.0
Groove 2007
Windows Vista
Outlook 2007
OneNote 2003
OneNote 2007
Office X for Mac
Zune software
Zune Live
Zoo Tycoon 2
Flight Simulator 2002
Dungeon Siege II

Cervo Technologies
The Right Source to Outsource

Oracle Database FAQS

Sharepoint Portal Server KB

Outlook 2007 Knowledge Base Articles

ADO.NET 1.1 Knowledge Base Articles

To make your data appear on a form, you bind a Microsoft Windows Forms DataGrid control to a DataTable object that is included in a DataSet object. After your data has appeared in the DataGrid control, you use the Tables.Clear method to remove the...


To make your data appear on a form, you bind a Microsoft Windows Forms DataGrid control to a DataTable object that is included in a DataSet object.

After your data has appeared in the DataGrid control, you use the Tables.Clear method to remove the DataTable object from the Tables collection of the bound DataSet object. However, although the bound DataSet object no longer contains any data, your original data continues to appear in the DataGrid control.

CAUSE

In a Microsoft Windows-based application, the CurrencyManager object manages a list of Binding objects. When you use a DataSet object together with a DataTable object for your data source, and you bind a DataGrid control to the DataSet object and the DataTable object, the CurrencyManager object manages this data source.

However, if you remove the DataTable object from the DataSet object, the related the CurrencyManager object that corresponds to the DataSet object is not updated. Therefore, the DataGrid control does not have this new information and the original data continues to appear in the DataGrid control.

WORKAROUND

To work around this problem, use the DataSource property instead of the SetDataBinding method to set the data source of the DataGrid control, as in the following sample code.

Microsoft Visual Basic .NET code
DataGrid1.DataSource = myDataSet.Tables("TableName")
Microsoft Visual C# .NET code
dataGrid1.DataSource = myDataSet.Tables["TableName"];

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section of this article.

MORE INFORMATION

Steps to reproduce the behavior

1.In Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, use Visual Basic .NET, Visual Basic 2005, Visual C# 2005, or Visual C# .NET to create a new Windows Application project. By default, Form1 is created.
2.Add a DataGrid control to Form1.
Note By default, the DataGrid control does not appear in Visual Studio 2005 toolbox. To obtain a DataGrid control, click Choose Toolbox Items on the Tools menu, click to select DataGrid on the .NET Framework Components tab, click Reset, and then click OK.
3.Add a Button object to Form1. By default, the Button1 object is created.
4.In design view, double-click Form1 to open the code for the Form1_Load event.
5.Add the following code before the Form1_Load event code to create a DataSet object.
Visual Basic .NET code
    ' Create a data source.
    Private myDataSet As DataSet = New DataSet
Visual C# .NET code
      // Create a data source.
      private DataSet myDataSet = new DataSet();
6. Replace the Form1_Load event code with the following code.
Visual Basic .NET code
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Add a DataTable object to the DataSet object.
        myDataSet.Tables.Add("MyTable")
        myDataSet.Tables(0).Columns.Add("OriginalColumn")
        myDataSet.Tables(0).Rows.Add(New Object() {"Original Data"})

        ' Bind the DataGrid control to the data source.
        DataGrid1.SetDataBinding(myDataSet, "MyTable")
    End Sub
Visual C# .NET code
   private void Form1_Load(object sender, System.EventArgs e)
   {
     // Add a DataTable object to the DataSet object.
     myDataSet.Tables.Add("MyTable");
     myDataSet.Tables[0].Columns.Add("OriginalColumn");
     myDataSet.Tables[0].Rows.Add(new Object[] {"Original Data"});

     // Bind the DataGrid control to the data source.
     dataGrid1.SetDataBinding(myDataSet, "MyTable");
   }
7.In Solution Explorer, right-click Form1, and then click View Designer.
8.In design view, double-click the Button1 object to add code for the Button1_Click event. Replace the code for the Button1_Click event with the following code.
Visual Basic .NET code
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Remove the DataTable object from the data source.
        myDataSet.Tables.Clear()
       
       ' Add a DataTable object to the DataSet object.
        myDataSet.Tables.Add("MyTable")
        myDataSet.Tables(0).Columns.Add("NewColumn")
        myDataSet.Tables(0).Rows.Add(New Object() {"New Data"})

        'DataGrid1.DataSource = myDataSet.Tables("MyTable")
        DataGrid1.SetDataBinding(myDataSet, "MyTable")
    End Sub
Visual C# .NET code
   private void button1_Click(object sender, System.EventArgs e)
   {
      // Remove the DataTable object from the data source.
      myDataSet.Tables.Clear();
   
      // Add a DataTable object to the DataSet object.
      myDataSet.Tables.Add("MyTable");
      myDataSet.Tables[0].Columns.Add("NewColumn");
      myDataSet.Tables[0].Rows.Add(new Object[] {"New Data"});
  
      // Bind the DataGrid control to the data source.
      dataGrid1.SetDataBinding(myDataSet, "MyTable");		
   }
9.On the Debug menu, click Start to run the application.
10.Click Button1. Notice that the original value appears in the DataGrid control.

REFERENCES

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:


APPLIES TO
Microsoft ADO.NET 2.0
Microsoft .NET Framework 1.1 Service Pack 1
Microsoft ADO.NET 1.0
Microsoft Visual Basic 2005
Microsoft Visual Basic .NET 2003 Standard Edition
Microsoft Visual Basic .NET 2002 Standard Edition
Microsoft Visual C# 2005 Express Edition
Microsoft Visual C# .NET 2003 Standard Edition
Microsoft Visual C# .NET 2002 Standard Edition

Keywords: 
kbvs2002sp1sweep kbcode kbpending kbdataview kbdatabinding kbcontrol kbsystemdata kbwindowsforms kbbug KB812919

Copyright © 2004 - 2007 Gridview.org, Inc. All rights reserved. Powered by Smart Web Content Management System