gpt4 book ai didi

c# - 使用 TableAdapter 重新加载数据

转载 作者:太空狗 更新时间:2023-10-30 01:08:09 24 4
gpt4 key购买 nike

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

如果以另一种形式进行了更改,我如何重新加载数据? (最好自动不使用刷新按钮)?

我正在使用 WinForms,后端是 Access 2007。

使用设计器将数据绑定(bind)到数据网格

最佳答案

首先,我会将 Fill 移动到一个单独的函数中:

public void LoadData()
{
this.usersTableAdapter.Fill(this.workOrdersDataSet.users);
}

然后当您执行加载事件时,您将调用该函数:

private void UserList_Load(object sender, EventArgs e)
{
LoadData();
}

如果您有另一个对数据执行更改的表单,您可以在另一个事件中调用此函数,类似于此。我在我的代码中使用 DialogResult:

private void OpenOtherForm()
{
DialogResult openForm = new OtherForm().ShowDialog();
if(openForm == DialogResult.OK)
LoadData();
}

更新过程完成后,在其他表单的代码中,包含一行代码来告诉您的主表单进行更新:

private void PerformUpdate()
{
try
{
// your update code goes here
DialogResult = DialogResult.OK; // this is the line that tells your other form to refresh
}
catch (Exception ex)
{
DialogResult = DialogResult.Abort;
}
}

然后使用 DialogResult 告诉您的主窗体仅在实际发生更新时才触发数据刷新。

关于c# - 使用 TableAdapter 重新加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10403150/

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