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



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • 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 "False" for this value, you will receive a build error message.
  4. 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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Visual Studio .NET, and then create a new Windows Application project.
  2. In Server Explorer, connect to the sample Pubs database, and then connect to the Authors table.
  3. 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.
  4. Add the following code to the Form1_Load event:
    DataSet11.Clear()
    OleDbDataAdapter1.Fill(DataSet11)
    					
  5. Add a TextBox control, and then bind the TextBox to the authors.au_lname field.
  6. Add a Button control, and then add the following code to the Button:
    BindingContext(DataSet11,"authors").EndCurrentEdit()
    BindingContext(DataSet11, "authors").AddNew()
    					
  7. 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).
  8. Compile and then run the code. When the form loads, notice that the text box contains the first lastname value from the Authors table.
  9. Click the button. Notice that the text box and the check box are not cleared.

Modification Type:MinorLast Reviewed:8/26/2005
Keywords:kbvs2002sp1sweep kbbug kbpending KB321504 kbAudDeveloper