Microsoft KB Archive/321504

= BUG: A check box is not cleared when you call the AddNew method on a DataSet =

Article ID: 321504

Article Last Modified on 8/26/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition

-



This article was previously published under Q321504



SYMPTOMS
When you call the AddNew method on a DataSet object that is bound to TextBox controls on a form, the text boxes are cleared as expected. However, if you add a CheckBox control to the binding in the same form, none of the controls are cleared when you call the AddNew method on the DataSet.



RESOLUTION
To work around this problem, explicitly set a default value for the Boolean data column in the .XSD file.

For example, assume that you use the Authors table from the sample Pubs database that is included with Microsoft SQL Server. Also, assume that the form that you use contains the following items:
 * TextBox control that is linked to the authors.au_lname field
 * CheckBox control that is linked to the authors.contract field

If you add a Button control that implements the AddNew method, the text box and the check box are not cleared when you click the button.

However, if you explicitly set a default value for the Boolean data column authors.contract, this problem does not occur.

To explicitly set a default value for the Boolean data column, use the XML Schema Definition (XSD) designer (in Design view or in Source view) when you edit the DataSet .xsd file that is generated.

To use the XSD designer, follow these steps:

Note These steps assume that you are using the Authors table of the Pubs database.
 * 1) In Solution Explorer of Microsoft Visual Basic .NET, view the XSD DataSet object that is already generated, and then double-click this object. Notice that the Authors table appears in a graphical representation on your work area.
 * 2) Select the contract (Boolean) element in the graphical representation of the Authors table.
 * 3) In the Properties window, set the default property to false.

Note This value is case-sensitive. If you use &quot;False&quot; for this value, you will receive a build error message.
 * 1) Recompile your project, and then test your form. Notice that the text box and the check box are cleared as expected.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Start Visual Studio .NET, and then create a new Windows Application project. In Server Explorer, connect to the sample Pubs database, and then connect to the Authors table. Use the Dataset Wizard to create a typed DataSet with this Authors table (which is connected through a SQL Server client or an OLE DB client). Accept all of the defaults, and then drag the connection to the end of the form.  Add the following code to the Form1_Load event: DataSet11.Clear OleDbDataAdapter1.Fill(DataSet11)  Add a TextBox control, and then bind the TextBox to the authors.au_lname field.  Add a Button control, and then add the following code to the Button: BindingContext(DataSet11,&quot;authors&quot;).EndCurrentEdit BindingContext(DataSet11, &quot;authors&quot;).AddNew </li> Add a CheckBox control to the form, and then bind the CheckBox to the authors.contract field (which is the binary field that will be used with the check box).</li> Compile and then run the code. When the form loads, notice that the text box contains the first lastname value from the Authors table.</li> Click the button. Notice that the text box and the check box are not cleared.</li></ol>

Keywords: kbbug kbpending kbvs2002sp1sweep KB321504

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.