BindSource bs = new BindSource;
bs.DataSource = null;
bs.DataSource = myBll.GetDataTable(); //获得数据表txtName.DataBindings.Add("Text", bs, "Name", true);
txtDescription.DataBindings.Add("Text", bs, "Description", true);bs.DataSource = null; //这行会报错:无法绑定到 DataSource 的属性或列 Name。参数名: dataMember
bs.DataSource = myBll.GetDataTable();
bs.DataSource = null;
bs.DataSource = myBll.GetDataTable(); //获得数据表txtName.DataBindings.Add("Text", bs, "Name", true);
txtDescription.DataBindings.Add("Text", bs, "Description", true);bs.DataSource = null; //这行会报错:无法绑定到 DataSource 的属性或列 Name。参数名: dataMember
bs.DataSource = myBll.GetDataTable();
bs.Sort = null; //如果没有这句,下面这行也会报错
bs.DataSource = null;我记不清当时加上 bs.DataSource=null 是什么目的了,但只知道当时不加就有问题,现在弄得非去掉这行不可。
bindingSource1.BindingComplete += new BindingCompleteEventHandler(bindingSource1_BindingComplete);private void bindingSource1_BindingComplete(object sender, BindingCompleteEventArgs e){
if (e.BindingCompleteContext == BindingCompleteContext.DataSourceUpdate && e.Exception == null)
e.Binding.BindingManagerBase.EndCurrentEdit();
}
删除 bs.DataSource = null;
绑定后 bs.ResetBindings(bool); // 如果数据架构改变则 true 否则为 false