468,720 Members | 1,873 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

Problem with REFRESH DataGridView

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;
}
}
Jun 27 '08 #1
4 4368
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
Jun 27 '08 #2
On 22 Apr, 11:14, Marc Gravell <marc.grav...@gmail.comwrote:
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;
}
Jun 27 '08 #3
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
Jun 27 '08 #4
On 22 Apr, 12:39, Marc Gravell <marc.grav...@gmail.comwrote:
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... :-(
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by thomasp | last post: by
6 posts views Thread by George | last post: by
3 posts views Thread by David Cartwright | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.