Problem with REFRESH DataGridView

C

Christian

Hi, i TRY to create a windows apllication that insert in a Access DB
name and surname; the Insert istruction Works but the the refresh of
DataGridView doesn't works...
the code is :
public Form1()
{
InitializeComponent();
}

#region Variabili
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\db1.mdb";
string querySelect = "select * from TabNomi";
string queryDel = "delete * from TabNomi";
DataTable dt = new DataTable();
BindingSource bsource = new BindingSource();
#endregion

private void Form1_Load(object sender, EventArgs e)
{
OleDbDataAdapter Dada = new OleDbDataAdapter(querySelect,
connString);
OleDbCommandBuilder Cbil = new OleDbCommandBuilder(Dada);
Dada.Fill(dt);

//BindingSource bsource = new BindingSource();
bsource.DataSource = dt;
dataGridView1.DataSource = bsource;
}

private void button1_Click(object sender, EventArgs e)
{
string queryInsert = "insert INTO TabNomi
VALUES('luca','pino')";
OleDbDataAdapter da = new OleDbDataAdapter(queryInsert,
connString);
OleDbCommandBuilder Cbil = new OleDbCommandBuilder(da);
da.Fill(dt);

//BindingSource s = new BindingSource();
bsource.DataSource = dt;
dataGridView1.DataSource = bsource;
}
}
 
M

Marc Gravell

If it isn't auto-updating, you could call ResetBindings() on the
BindingSource; you could also change the binding (your current lines are
trivial updates - i.e. they don't change anything, so it won't refresh).

Marc
 
C

Christian

If it isn't auto-updating, you could call ResetBindings() on the
BindingSource; you could also change the binding (your current lines are
trivial updates - i.e. they don't change anything, so it won't refresh).

Marc

i put the istruction ResetBindings() but the datagridview don't
refresh...

private void button2_Click(object sender, EventArgs e)
{
string queryInsert = "insert INTO TabNomi
VALUES('marco','pino')";
OleDbDataAdapter da = new OleDbDataAdapter(queryInsert,
connString);
OleDbCommandBuilder Cbil = new OleDbCommandBuilder(da);
da.Fill(dt);

bsource.ResetBindings(false);

bsource.DataSource = dt;
dataGridView1.DataSource = bsource;
}
 
M

Marc Gravell

In that case... are you sure that the DataTable has been updated by the
adapter? Try manually finding (loop or whatever) the record in the "dt"
DataTable; is it there?

Marc
 
C

Christian

In that case... are you sure that the DataTable has been updated by the
adapter? Try manually finding (loop or whatever) the record in the "dt"
DataTable; is it there?

Marc

isee that the DataTable doesn't Update.... but the insert in Access DB
works... :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top