Sql 使用this.TableManager.UpdateAll更新数据库,但出现重复键错误
我尝试用这个.TableManager.UpdateAll更新数据库。添加的第一个客户机很好,但是当我想添加新客户机时,出现了重复密钥错误。代码如下:Sql 使用this.TableManager.UpdateAll更新数据库,但出现重复键错误,sql,sql-server,database,data-binding,visual-studio-2012,Sql,Sql Server,Database,Data Binding,Visual Studio 2012,我尝试用这个.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 tw
//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());
}
是否已将主键列设置为列?如果是这样,请刷新数据集或手动将设计器中的列更改为
AoutoIncrement=true
。非常感谢您的帮助