Updating a datagrid

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();
 
L

Lonifasiko

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.
 

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