[分享]Textbox与label的数据绑定
例: 数据库path包含表users,users为
ID passwork
1 a
2 b
private System.windows.form Textbox=new System.windows.form Textbox1;
private System.windows.form label=new System.windows.form label1;
private System.wivdows.form dataGrid=new System.windows.form dataGrid1;
string sql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\My Documents\\path.mdb";
string selec="SELECT * from usesrs where ID="+Textbox1.text ;
OleDbConnection conn = new OleDbConnection(sql);
OleDbDataAdapter dataa = new OleDbDataAdapter(selec, conn);
conn.Open();
DataSet dataset1 = new DataSet();
dataa.Fill(dataset1, "users");
conn.Close();
dataGrid1.SetDataBinding(dataset1, "users");
label1.DataBindings.Clear();
label1.DataBindings.Add("Text",dataset1,"users.passwork");
Textbox1.text="1";
label1.text="a";
Textbox1.text="2";
label1.text="b";