导致集合中的两个绑定绑定到同一个属性

cherish_human cherish_human 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Drawing.Imaging;


namespace SchoolMate.Windows
{
public partial class UserInfo : Form
{
public UserInfo()
{
InitializeComponent();
}
DataSet ds = new DataSet();
SqlConnection cn = null;
Link.SQLConnection sqlcn = new SchoolMate.Link.SQLConnection();
SqlDataAdapter da1;
BindingSource myBindingSource;


private void UserInfo_Load(object sender, EventArgs e)
{
cn = sqlcn.SQlconnection();
cn.Open();

da1 = new SqlDataAdapter("SELECT * FROM webapp.UserInfo", cn);
da1.Fill(ds, "UserInfo");

myBindingSource = new BindingSource();
myBindingSource.DataSource = ds.Tables["UserInfo"];


this.textBox1.DataBindings.Add("Text", myBindingSource, "Name");
this.textBox2.DataBindings.Add("Text", myBindingSource, "Sex");
this.dateTimePicker1.DataBindings.Add("Value", myBindingSource, "RegDate");
this.textBox3.DataBindings.Add("Text", myBindingSource, "QQ");
this.textBox4.DataBindings.Add("Text", myBindingSource, "Address");


InitializationControl();








}


private void btnCancel_Click(object sender, EventArgs e)
{
ds.RejectChanges();
//ds.Clear();
da1.Fill(ds, "UserInfoDetail");

}

private void btnModify_Click(object sender, EventArgs e)
{
Control();

}
private void InitializationControl()
{
this.textBox1.ReadOnly = true;
this.textBox2.ReadOnly = true;
this.textBox3.ReadOnly = true;
this.textBox4.ReadOnly = true;



this.btnSave.Enabled = false;
this.btnCancel.Enabled = false;
}
private void Control()
{
this.textBox1.ReadOnly = false;
this.textBox2.ReadOnly = false;
this.textBox3.ReadOnly = false;
this.textBox4.ReadOnly = false;


this.btnSave.Enabled = true;
this.btnCancel.Enabled = true;

}

private void btnSave_Click(object sender, EventArgs e)
{

if(this.btnSave.CanSelect==true)
{
Method.GetAccount g=new SchoolMate.Method.GetAccount();
Attribute.AccountInfo a=new SchoolMate.Attribute.AccountInfo();
a.Name=this.textBox1.Text;
a.Sex=this.textBox2.Text;
a.QQ=this.textBox3.Text;
a.Address=this.textBox4.Text;

if(g.AddUser(a)==1)
{
MessageBox.Show("已经成功修改信息!", "提示");
}
else
{
MessageBox.Show("修改失败!","提示");
}



}

}

private void btnClass_Click(object sender, EventArgs e)
{
this.Hide();
Windows.ClassInfo i = new ClassInfo();
i.Show();

}

private void btnPhoto_Click(object sender, EventArgs e)
{
this.Hide();
Windows.Photo i = new Photo();
i.Show();

}

private void btnMessage_Click(object sender, EventArgs e)
{
this.Hide();
Windows.Message i = new Message();
i.Show();
}

private void btnSearch_Click(object sender, EventArgs e)
{
this.Hide();
Windows.Search i = new Search();
i.Show();
}

private void btnView_Click(object sender, EventArgs e)
{

}




}
}



我想问一下这段代码,为什么我在调试的时候它提示说:
this.textBox1.DataBindings.Add("Text", myBindingSource, "Name"); 这句代码
这将导致集合中的两个绑定绑定到同一个属性。
参数名: binding


是什么原因,如何解决?急!
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
cherish_human
.NET Framework 17,748 成员 24,324 内容