Hey there, im stuck now with the datagridview not being able to discard the old headings in it and load another table in access.
this is how the test program works
i have 2 buttons.
start the program, and press one button - the datatable loads
close the program, and press the other button - the other datatable loads
but now, start the program press the one button - the datatable loads, Now,
without exiting press the second button, and it only adds the headings of the other table?
i have no idea how to "reset" the datagridview.
here is my code
private void button3_Click(object sender, EventArgs e)
{
string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb";
string query = "SELECT * FROM Table1"; <------- the one table
//create an OleDbDataAdapter to execute the query
dAdapter = new OleDbDataAdapter(query, connString);
//create a command builder
OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
//fill the DataTable
dAdapter.Fill(dTable);
//the DataGridView
DataGridView dgView = new DataGridView();
//BindingSource to sync DataTable and DataGridView
BindingSource bSource = new BindingSource();
//set the BindingSource DataSource
bSource.DataSource = dTable;
//set the DataGridView DataSource
dataGridView1.DataSource = bSource;
}
private void button2_Click(object sender, EventArgs e)
{
string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb";
string query = "SELECT * FROM Expenditure"; <--- second table
//create an OleDbDataAdapter to execute the query
dAdapter = new OleDbDataAdapter(query, connString);
//create a command builder
OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
//fill the DataTable
dAdapter.Fill(dTable);
//the DataGridView
DataGridView dgView = new DataGridView();
//BindingSource to sync DataTable and DataGridView
BindingSource bSource = new BindingSource();
//set the BindingSource DataSource
bSource.DataSource = dTable;
//set the DataGridView DataSource
dataGridView1.DataSource = bSource;
}
Thank you. =)
Ruan