can somebody tell me the codes for updating the datagridview records..
here's what i wanna do.
for example there are 3 columns name , middle , last.
i want to update last but the problem is my datagridview doesnt update and still remain the same record but no errors..

Dani AI

Generated

This thread correctly points to a data-binding mismatch, but a few concrete steps are often missing. The typical lifecycle is: a cell edit must be committed to the bound list, the bound list must have pending changes visible, and then those changes must be pushed to the database. Failure can happen at any of those stages.

A minimal sequence that fixes the most common problems is:

// commit any pending cell edit into the bound list
dataGridView1.EndEdit();
bindingSource1.EndEdit();

// push DataTable changes to the database
using (var adapter = new SqlDataAdapter(selectCommand, connection))
{
    var builder = new SqlCommandBuilder(adapter);
    adapter.Update(dataSet.Tables["People"]);
}

Troubleshooting checklist:

  • Confirm the grid is bound to a DataTable/BindingSource and not to a read-only projection.
  • Ensure the BindingSource/DataTable has Insert/Update/Delete commands (SqlDataAdapter must have commands or use SqlCommandBuilder).
  • Do not call DataTable.AcceptChanges() before calling DataAdapter.Update(); AcceptChanges clears row states so nothing gets persisted.
  • For controls that keep edits open (checkboxes, comboboxes), force commit from the current cell (EndEdit/CommitEdit) or handle CurrentCellDirtyStateChanged.
  • Inspect exceptions from adapter.Update; wrap Update in try/catch and log row state and errors for failing rows.
  • If UI still looks stale after an update, re-fill the table from the database or call ResetBindings on the BindingSource to re-sync display.

References: BindingSource.EndEdit for committing bound edits (BindingSource.EndEdit) and DataAdapter.Update for persisting changes (DataAdapter.Update). These address the commit/update phases omitted in earlier replies by and .

Recommended Answers

All 3 Replies

you can try
1.) datagrid.Refresh()

or

2.) reset datasource bindingsource

can somebody tell me the codes for updating the datagridview records..
here's what i wanna do.
for example there are 3 columns name , middle , last.
i want to update last but the problem is my datagridview doesnt update and still remain the same record but no errors..

You See , if you dont Show us your Code, we will not know why your update does not work

csy is probably correct. Here's how it works:

You tell a datagrid to display certain data. That data is sitting somewhere else, like a database, then a copy of it is made to display in that datagrid.

After that, the datagrid is told (by the user) to change the data (last name in this case), which it does. The data in the database has now changed.

However, the datagrid has a COPY of the data, so just because you changed the database doesn't mean the datagrid knows about the change.

The way you tell the datagrid to get the fresh data is, right after the data changes, you call grid.Refresh, or give it a new datasource like csy said.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.