Hi sushu,
Sorry for the late reply. The root cause is that you call the AcceptChanges method of the DataTable before the data is updated to database. The msdn document said:
When AcceptChanges is called, any DataRow object still in edit mode successfully ends its edits. The DataRowState also changes: all Added and Modified rows become Unchanged, and Deleted rows are removed.
So the edit states are lost, the DataAdapter would think there is not row modified, added or deleted and the data would not be updated to database. You can get more about AcceptChanges from: http://msdn.microsoft.com/en-us/library/system.data.datatable.acceptchanges.aspx
To solve the issue, we need to remove the calling of the AcceptChanges method as follows:
private void saveToolStripButton_Click(object sender, EventArgs e)
{
Validate();
dataGridView1.EndEdit();
transactionsBindingSource.EndEdit();
transactionsTableAdapter.Update(budgetDataSet);
}
By the way, the id column is auto incremented, so we’d better have this column read only to disallow the user to fill some useless values. We also need to add a refresh button to allow user to fetch the data from database again to see if the data is updated successfully.
Let me know if this does not help.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.