Why it doesn't save changes into datatable from datagridview?

北城余情 提交于 2019-12-05 18:50:22

When you set this.Update(competitorDataSet.Odrasli); the TableAdapter updates the changes from DataTable (news, deleted, updated rows) to the database.

Since you call competitorDataSet.Growns.AcceptChanges(); before TableAdapter.Update, all changes in the table are already accepted and TableAdapter has nothing to update.

So just remove

competitorDataSet.Growns.AcceptChanges();

Also, if you set this.grownsTableAdapter.Adapter.AcceptChangesDuringUpdate = true before grownsTableAdapter.Update(competitorDataSet.Odrasli);, the changes will be accepted and so you don't need to accept changes yourself (and it seems to me that default value is True so I am not sure this line is required)

You are not editing the data with the datagridview, you are changing the dataset using the textboxes, I think this is your example with the manual fill...

I will presume that the code you want to use to update the database begins at this line:

this.dataGridView1.DataSource = competitorDataSet.Growns;

I suspect your problem is in the following code block (explanations in code comments):

//why rebind the datagridview?
//this line should be removed
this.dataGridView1.DataSource = competitorDataSet.Growns;

//why call this here? validation should be done prior 
//to adding the new row to the datatable
//this line should be removed
this.Validate();

this.grownsBindingSource.EndEdit();
if (dataGridView1.BindingContext[competitorDataSet.Growns] != null)
{
dataGridView1.BindingContext[competitorDataSet.Growns].EndCurrentEdit();
}

//reverse the order of these 2 lines
this.grownsTableAdapter.Update(competitorDataSet.Odrasli);
this.grownsTableAdapter.Adapter.AcceptChangesDuringUpdate = true;
/* like this:
this.grownsTableAdapter.Adapter.AcceptChangesDuringUpdate = true;
this.grownsTableAdapter.Update(competitorDataSet.Odrasli);
 */

If this does not solve your problem, please post the binding code for your datagriview.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!