我尝试使用this.TableManager.UpdateAll更新数据库。添加的第一个客户端很好,但是当我想添加一个新客户端时,我得到了重复的密钥错误。这是代码:
//using a try command so if there is an exception, it will display it
try
{
//check if there are any changes prevents someone pressing save twice and you may get duplicate entries in database
if (this.allensCroftDataSet.HasChanges())
{
//It will then check if a row has been added:
if ((this.TableManager.UpdateAll(this.allensCroftDataSet) > 0))
{
//And it will then display a message box saying “saved”.
MessageBox.Show("Saved.");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}