gpt4 book ai didi

C# 数据库合并/复制

转载 作者:行者123 更新时间:2023-11-30 18:40:49 26 4
gpt4 key购买 nike

我想为基于 MS Access 的应用程序创建一个复制解决方案。我有 2-4 个站点在数据库中创建内容,但它们都处于离线状态。到目前为止我的解决方案:

从文件菜单调用的函数:

class main
{
private void menuItemMergeUserData_Click(object sender, EventArgs e)
{
OpenFileDialog openDataFileDialog = new OpenFileDialog();

openDataFileDialog.Title = "Select UserData file to merge";
openDataFileDialog.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
openDataFileDialog.Filter = "Database files (*.mdb)|*.mdb|All files (*.*)|*.*";
openDataFileDialog.RestoreDirectory = true;

if (openDataFileDialog.ShowDialog() == DialogResult.OK)
{
ExternalUserManager UserManager = new ExternalUserManager(openDataFileDialog.FileName, CompanyID, dbManager);
if (UserManager.MergeUserTables())
MessageBox.Show("UserData merged!", "UserData");
}
openDataFileDialog.Dispose();
}
}

在类 ExternalUserManager 中调用的函数

 public bool MergeUserTables()
{
bool bOk = true;

try
{
//databaseManager.CallMacro(dbMyFileName);

conUserData.Open();


daClass.Fill(dsUserData, "Class");
daClassUsers.Fill(dsUserData, "ClassUsers");
daCompany.Fill(dsUserData, "Company");
daCurriculum.Fill(dsUserData, "Curriculum");
daCurriculumExercises.Fill(dsUserData, "CurriculumExercises");
daCurriculumMissions.Fill(dsUserData, "CurriculumMissions");
daCurriculumTasks.Fill(dsUserData, "CurriculumTasks");
daUserModes.Fill(dsUserData, "UserModes");
daUserProfile.Fill(dsUserData, "UserProfile");
daUsers.Fill(dsUserData, "Users");
bOk = databaseManager.MergeDataSet(dsUserData);

}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Reading UserData");
}
finally
{
conUserData.Close();
}

return bOk;
}

在类 DatabaseManager 中调用的函数

public bool MergeDataSet(DataSetUserContent dsExternalUserContent)
{
bool bOk = false;
try
{

this.dsUserContent.MergeFailed += new MergeFailedEventHandler(OnMergeFailed);
this.dsUserContent.Merge(dsExternalUserContent);
if(this.dsUserContent.HasChanges())
bOk = SaveUsers();
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "LogData Merge");
}
finally
{
conLogData.Close();
}

return bOk;
}

数据集按照我的意愿合并,但是导入数据库中的新行没有保存到数据库中???

已搜索此问题的解决方案和 some say设置 AcceptChangesDuringFill = false 。试过了,但这使得导入数据库中的所有行都作为新行添加到源数据库中。

最佳答案

如果所有应用程序都离线,为什么不直接将 mdb 文件复制过来?

这很粗糙,我知道,但它应该可以正常工作。

关于C# 数据库合并/复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7723612/

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