datatable资源的释放问题
我做了个测试:
public partial class Form2 : Form
{
DataTable MyDataTable;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MyDataTable = new DataTable();
MyDataTable.Columns.Add( "id ", typeof(int));
MyDataTable.Columns.Add( "name ", typeof(string));
MyDataTable.Rows.Add(1, "a ");
MyDataTable.Rows.Add(2, "b ");
MyDataTable.Rows.Add(3, "c ");
textBox1.DataBindings.Add( "text ", MyDataTable, "id ");
dataGridView1.DataSource = MyDataTable;
}
private void button2_Click(object sender, EventArgs e)
{
MyDataTable = new DataTable();
MyDataTable.Columns.Add( "field1 ", typeof(int));
MyDataTable.Columns.Add( "fiedl2 ", typeof(string));
MyDataTable.Rows.Add(1, "x ");
MyDataTable.Rows.Add(2, "y ");
MyDataTable.Rows.Add(3, "z ");
MyDataTable.AcceptChanges();
textBox2.DataBindings.Add( "text ", MyDataTable, "field1 ");
dataGridView2.DataSource = MyDataTable;
}
}
点button1时,新建datatable,并绑定。绑定到textbox1, datagridview1