如何解决此错误信息? [英] How to solve this error message ?

查看:105
本文介绍了如何解决此错误信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
当单击按钮以在datagridview和文本框中显示数据时,数据显示没有问题,但是再次单击时将出现此消息,并且项目需要关闭

此错误消息:

这将导致集合中的两个绑定绑定到相同的属性.
参数名称:绑定.

这是我的代码:

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 :

//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(); 
       }
   }

推荐答案

由于您尚未共享代码,因此根据您所说的内容,听起来您在程序中多次调用同一代码重新加载数据源-结果,代码使用相同的参数调用Control.DataBindings.Add twice.这将尝试向DataBindings集合添加重复的绑定-导致错误.

一种解决方案是在添加新绑定之前清除DataBindings集合,例如:
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:
Me.TextBox1.DataBindings.Clear();
Me.TextBox1.DataBindings.Add("Text", myDataTable, "Col1Name")


这篇关于如何解决此错误信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆