c# - Datagridview 不保存对数据库的更改

标签 c# datagridview

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/

相关文章:

c# - 在 comboBox 中列出时将 DateTime String 转换为 Date-only

c# - DataGridView List<T> 列?

.net - 如何在 DataGridView 中选择多个单元格

c# - 大型 RegEx 匹配导致程序挂起

java - 如何在不使用第三方库的情况下转义java字符串中的unicode字符

.net - 验证 DataGridView 单元格

c# - 窗体。使用 BindingNavigator 时如何使 DataGridView 写入单元格值

c# - 如何分解/运行大型 SQL 查询?

c# - 从 C# 调用存储过程时出错

c# - 二进制搜索算法查找排序数组中值的变化