Tuesday 25 September 2012

This causes two bindings in the collection to bind to the same property. Parameter name:binding

"ArgumentException was unhandled. This causes two bindings in the collection to bind to the same property. Parameter name:binding"..Here I Got The Exception When I Click On The "Display" Button Two Times. That Means I Clicked On Display Button To Display The Data In The DataGridView i.e., one time And I Had updated One Record And To Display The Updated Record Again I Had Clicked On The "Display" Button, Then I Got The "ArgumentException was unhandled" Because Of That -As the error message suggests, that The Code is Calling Control.DataBindings. When I Click On "Display" Button It Calls twice with what amounts to the same parameters. One way this might happen is if you call the same code more than once in your program to reload your data source for some reason.

For One Click On The "Display" Button..It Displays Data In The DataGridView As Shown Below:



For The Second Click On Display Button It Shows The Exception As Show Below:



Rectification Of ArgumentException was unhandled:

The issue is that we are binding the same properties of our controls multiple times. Our result set has the same schema every time then there's no need to create a new DataTable/DataSet every time. Just We Are binding to the one DataTable/DataSet and then clear and refill it each time. Our controls remain bound to the same data source the whole time and We just change the data in the source. If We really do need to rebind the controls multiple times then We must remove the old bindings first. So To Remove The Old Bindings We Are Using DataBindings.Clear()..

Now We Can Click On Display Button As Many Times We Need..It Doesnot show Exception..

Here The DataBinding Is Created One Time As We Click On Display Button One Time. When We Click "Display" Button Then The Data Is Already Bind To The Dataset.That means THe Binding Is  Happened At First Click Only. As The Binding Is Happened It Cannot accept the DataBinding For The Next Time Button Clicking Event. So We Have To Clear The First Created DataBinding And Again Create New Databinding For Our Dataset. Now It Will Work Without any exceptions..


Now The Resultant Form Runs SuccessFully As  Below :







1 comment :

  1. Could you please post the code for updating a record (button click). I have an issue updating a SQL records. I was able to insert records without any issues when the "save" button is clicked but I also want to update another record from a different table at the same time.

    ReplyDelete

Note: only a member of this blog may post a comment.