Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hii, everybody,
when click button to display data in datagridview and textboxes data show with no problem ,but when click again this message appear and project need to close

this error message :

this causes two bindings in the collection to bind to the same property.
parameter name:binding.

this is my code :
C#
//check the connection to database
       if (this.datc.fnGetDataConnection())
       {
            this.dataGrid1.ReadOnly = true;
           this.dataGrid1.DataSource = datc.dSet.Tables["student"];
           // DataBinding of TextBoxes
           fnGetDataBindingForTextBoxes();
                     fnSetCurrencyManager();
           //Record numbers in the StatusBar
           fnDisplayRecordNumbers();
       }
       else
       {
           MessageBox.Show("Connection failed...");
           Application.Exit(); 
       }
   }
Posted
Updated 18-Sep-12 20:40pm
v2
Comments
arshad alam 19-Sep-12 2:15am    
can you share your code and error snapshot with us ?
mhassan083 19-Sep-12 2:43am    
the text of error message is exist

1 solution

Since you have not shared your code, based on what you say, it sounds like you call the same code more than once in your program to reload your data source - as a result, the code is calling Control.DataBindings.Add twice with the same parameters. This would attempt to add a duplicate binding to the DataBindings collection - leading to error.

One solution is to clear the DataBindings collection before you add your new binding, something like:
C#
Me.TextBox1.DataBindings.Clear();
Me.TextBox1.DataBindings.Add("Text", myDataTable, "Col1Name")
 
Share this answer
 
Comments
mhassan083 19-Sep-12 2:52am    
now, code shared
Sandeep Mewara 19-Sep-12 3:18am    
Try to put:
this.dataGrid1.DataBindings.Clear();

before assigning datasource. See if it helps.
mhassan083 19-Sep-12 3:31am    
i do that in textboxes and success in the same time message does not appear but
satus bar repeated data on status bar???
Sandeep Mewara 19-Sep-12 3:36am    
???


Not clear. New issue?
mhassan083 19-Sep-12 3:46am    
i mean when click again data on staus bar on the form duplicated after each click
(1 of record 1 one of record 1 one of record 1....)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900