Updating a datagrid

  • Thread starter Thread starter fix
  • Start date Start date
F

fix

Hi,

I am using the DataGrid to display a DataTable. I need to update the
grid every time I update the table in the database. Here is my code to
do that. The problem is that every time the code below runs, the old
rows stays and the new rows are added. Is there any way that I can clear
the grid before refreshing? I tried setting the datasource to null, but
that doesn't help.

Thanks.
fix.

=========================

string SelectSQL = "SELECT * FROM Fruits";
SqlCeCommand SelectCmd = new SqlCeCommand(SelectSQL, Connection);
SqlCeDataAdapter da = new SqlCeDataAdapter(SelectCmd);
try
{
da.Fill(ds);
}
catch (SqlCeException ex)
{
DisplaySQLCEErrors(ex);
}

dt = ds.Tables[0];

GridFruits.DataSource = dt;
GridFruits.Refresh();
 
Hi,
I think Refresh and Update method in all controls are only for control
redrawing purpose.

I would like to see the code where you declare DataSet ds and DataTable
dt. I understand you need something like this:

ds.Clear();
ds.Tables[0].Clear();

Please do check the new data you bring is really "new". Debug and see
data inside ds.Tables[0].

Regards.
 
Back
Top