[求助]datatable的reset怎么用?
我的数据库里有两个数据表,程序界面里有一个下拉框,想通过用户对下拉框项目(表格)的选择来在同一个窗口中绑定显示不同的数据表,结果是第一个数据表显示正常,将datatable reset并重新填充绑定后,文本框里面根本就不能显示新数据表里面的内容了,这是为什么,请各位朋友帮帮我!我的代码如下:private void combo1_SelectedIndexChanged(object sender, EventArgs e)
{
string Strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Application.StartupPath + "\\abc.mdb";
DataTable Tbl = new DataTable();
switch (combo1.SelectedItem.ToString())
{
case "aa":
this.textBox1.DataBindings.Clear();//移除数据绑定
this.textBox2.DataBindings.Clear();
this.textBox3.DataBindings.Clear();
this.textBox4.DataBindings.Clear();
this.textBox5.DataBindings.Clear();
this.textBox6.DataBindings.Clear();
Tbl.Reset();//数据表初始化
string StrSql = "SELECT * FROM aa";
OleDbDataAdapter da = new OleDbDataAdapter(StrSql,Strcon);//定义DataAdapter
da.Fill(Tbl);//填充表格
this.textBox1.DataBindings.Add("Text", Tbl, Tbl.Columns[0].Caption);//创建文本框字段绑定
this.textBox2.DataBindings.Add("Text", Tbl, Tbl.Columns[1].Caption);
this.textBox3.DataBindings.Add("Text", Tbl, Tbl.Columns[2].Caption);
this.textBox4.DataBindings.Add("Text", Tbl, Tbl.Columns[3].Caption);
this.textBox5.DataBindings.Add("Text", Tbl, Tbl.Columns[4].Caption);
this.textBox6.DataBindings.Add("Text", Tbl, Tbl.Columns[5].Caption);
break;
case "bb":
this.textBox1.DataBindings.Clear();
this.textBox2.DataBindings.Clear();
this.textBox3.DataBindings.Clear();
this.textBox4.DataBindings.Clear();
this.textBox5.DataBindings.Clear();
this.textBox6.DataBindings.Clear();
Tbl.Reset();
string StrSql1 = "SELECT * FROM bb";
OleDbDataAdapter da1 = new OleDbDataAdapter(StrSql1,Strcon);
da1.Fill(Tbl);
this.textBox1.DataBindings.Add("Text", Tbl, Tbl.Columns[0].Caption);
this.textBox2.DataBindings.Add("Text", Tbl, Tbl.Columns[1].Caption);
this.textBox3.DataBindings.Add("Text", Tbl, Tbl.Columns[2].Caption);
this.textBox4.DataBindings.Add("Text", Tbl, Tbl.Columns[3].Caption);
this.textBox5.DataBindings.Add("Text", Tbl, Tbl.Columns[4].Caption);
this.textBox6.DataBindings.Add("Text", Tbl, Tbl.Columns[5].Caption);
break;
}
}