Datagridview 未将更改保存到数据库。
只是在表单中,而不是在数据库中。
我已检查数据库属性,并将复制到输出目录
设置为如果更新则应对
。
这是我的代码:
public partial class ClientsManager : Form
{
public ClientsManager()
{
InitializeComponent();
}
private void clientsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
try
{
this.Validate();
this.clientsBindingSource.EndEdit();
//this.tableAdapterManager.UpdateAll(this.databaseDataSet);
this.clientsTableAdapter.Update(this.databaseDataSet.Clients);
MessageBox.Show("Changes has been Saved!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void ClientsManager_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'databaseDataSet.Clients' table. You can move, or remove it, as needed.
this.clientsTableAdapter.Fill(this.databaseDataSet.Clients);
}
到目前为止,我读过的大多数解决方案都是关于 EndEdit()
和 Update()
的。我的代码中有这个,但仍然无法正常工作。
最佳答案
您可以创建一个名为“SAVE”的新按钮,并将以下代码放入其中。
你的数据表名称.update(这里是你的数据表名称)
希望有帮助。
关于c# - Datagridview 不保存对数据库的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32297696/