gpt4 book ai didi

c# - 如何使用 TableAdapter 进行更新?

转载 作者:行者123 更新时间:2023-11-30 12:31:10 25 4
gpt4 key购买 nike

我正在 WindowsApplication 中编写一个使用数据库的程序。我使用 DataGridView 显示数据库值。目前,我希望有可能通过 DataGridView 更新数据库,因此我写了这段代码:

    private void MainForm_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'databaseDataSet1.products' table. You can move, or remove it, as needed.
this.productsTableAdapter1.Fill(this.databaseDataSet1.products);
}

private void upButton1_Click(object sender, EventArgs e)
{
this.productsTableAdapter1.Update(this.databaseDataSet1.products);
MessageBox.Show("הנתונים עודכנו בהצלחה!");
}

问题是没有将值更新到数据库中。如果有人可以帮助我解决这个问题,或者更好地解释如何使用 DataGridView,我会很高兴,因为我在 Internet 上没有找到任何有用的东西。

最佳答案

        this.Validate();
this.productsBindingSource.EndEdit();
this.productsTableAdapter1.Update(this.databaseDataSet1.products);
//this.productsTableAdapter1.UpdateAll(this.databaseDataSet1);

关于c# - 如何使用 TableAdapter 进行更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14292727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com