Microsoft Knowledge Base Email Alertz

KBAlertz.com: (326440) - When you call the AddNew method to add a new record to a DataTable object that the CurrencyManager object manages, the method silently fails and does not advance to a new record.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 326440 - Last Review: December 3, 2007 - Revision: 7.2

BUG: AddNew method of CurrencyManager fails with bound CheckBox

This article was previously published under Q326440

On This Page

SYMPTOMS

When you call the AddNew method to add a new record to a DataTable object that the CurrencyManager object manages, the method silently fails and does not advance to a new record.

CAUSE

This problem occurs under the following circumstances:
  • The form contains a CheckBox control whose Checked property is bound to a DataColumn object. -and-

  • The DefaultValue property of the DataColumn object is set to System.DBNull.
This problem may occur even if the column in the underlying database has a default value of True or False.

The Checked property of a CheckBox control can only accept boolean values (True or False) and does not understand Null. Therefore, you cannot position CurrencyManager on a new row when the DefaultValue of the DataColumn is set to System.DBNull.

RESOLUTION

To resolve this problem, programmatically modify the DataColumn object in the DataTable, and then set its DefaultValue property to True or to False.

NOTE: This does not modify the property in the underlying database. This only applies to the instance of the DataTable class that the CurrencyManager is using.

For example, to set the DefaultValue of the Discontinued column in the DataTable object, follow these steps:
  1. Follow steps 1 through 9 of the "Steps to Reproduce the Behavior" section of this article.
  2. Add the following code at the end of the BindControls procedure:
    If dt.Columns("Discontinued").DefaultValue Is System.DBNull.Value Then
       dt.Columns("Discontinued").DefaultValue = False 'or True if it should be checked by default
    End If
    					
  3. On the Debug menu, click Start.
  4. Click the button. Notice that the controls are cleared when the CurrencyManager advances to a new record.

STATUS

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

MORE INFORMATION

Steps to Reproduce the Behavior

NOTE: The following code sample assumes that Microsoft SQL Server is installed locally and that SQL Server contains a copy of the Northwind database.
  1. Create a new Visual Basic .NET or Visual Basic 2005 Windows application. By default, Form1 is created.
  2. Add two TextBox controls, a Button control, and a CheckBox control to the form.
  3. On the View menu, click Code to view the form's Code module window.
  4. Add the following Imports statement at the top of the Code window:
    Imports System.Data.OleDb
    					
  5. Add the following code to the Form module:
    Private ds As New DataSet()
    Private dt As DataTable
    Private da As OleDbDataAdapter
    Private cm As CurrencyManager
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim strConnection As String
       strConnection = "Provider=SQLOLEDB;Data Source=localhost;" & _
                       "Initial Catalog=Northwind;Integrated Security=SSPI"
       da = New OleDbDataAdapter("SELECT * FROM Products", strConnection)
       da.Fill(ds, "Products")
       dt = ds.Tables(0)
       BindControls()
       cm = CType(Me.BindingContext(dt), CurrencyManager)
    End Sub
    
    Private Sub BindControls()
       TextBox1.DataBindings.Add("Text", dt, "ProductID")
       TextBox2.DataBindings.Add("Text", dt, "ProductName")
    End Sub
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       cm.AddNew()
    End Sub
    					
  6. On the Debug menu, click Start. Notice that the form populates with data from the first record of the Products table.
  7. Click the button. Notice that the controls are cleared when the CurrencyManager advances to a new record.
  8. Close the form, and then return to Design view.
  9. Add the following line of code to the end of the BindControls procedure:
    Checkbox1.DataBindings.Add("Checked", dt, "Discontinued")
    					
  10. On the Debug menu, click Start.
  11. Click the button. Notice that the controls retain their current values and that the CurrencyManager does not advance to a new record.

REFERENCES

For more information, click the following article number to view the article in the Microsoft Knowledge Base:
321504  (http://kbalertz.com/Feedback.aspx?kbNumber=321504/ ) BUG: A check box is not cleared when you call the AddNew method on a DataSet

APPLIES TO
  • Microsoft .NET Framework Class Libraries 1.1
  • Microsoft .NET Framework Class Libraries 1.0
  • Microsoft .NET Framework 2.0
  • Microsoft Visual Basic 2005 Express Edition
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
Keywords: 
kbbug kbnofix kbctrl kbvs2002sp1sweep kbvs2005applies kbvs2005swept KB326440
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please