Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用this.TableManager.UpdateAll更新数据库,但出现重复键错误_Sql_Sql Server_Database_Data Binding_Visual Studio 2012 - Fatal编程技术网

Sql 使用this.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

我尝试用这个.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());
        }

是否已将主键列设置为列?如果是这样,请刷新数据集或手动将设计器中的列更改为
AoutoIncrement=true
。非常感谢您的帮助