由于违反约束而中止PRIMARY KEY必须是唯一的..错误 [英] Abort due to constraint violation PRIMARY KEY must be unique..error

查看:240
本文介绍了由于违反约束而中止PRIMARY KEY必须是唯一的..错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于约束违反而中止,PRIMARY KEY必须是唯一的,任何人都告诉我这是什么错误.....

Abort due to constraint violation PRIMARY KEY must be unique, any one tell me what error this.....

private void tsbtnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                frmAddEditEvents obj = new frmAddEditEvents();
                obj.ShowDialog();
                    SQLiteConnection connection = new SQLiteConnection(connectionString);
                    if (grdEvents.Rows.Count > 1 && grdEvents.SelectedRows[0].Index != grdEvents.Rows.Count - 0)
                    {
                        delcmd.CommandText = "UPDATE AddEvent SET ID=" + grdEvents.SelectedRows[0].Cells[0].Value.ToString()+ "";
                        connection.Open();
                        delcmd.Connection = connection;
                        delcmd.ExecuteNonQuery();
                        connection.Close();  

                        grdEvents.Update();
                        MessageBox.Show("Row updated");
                    }
                else
                {
                    MessageBox.Show("Please select any record to update");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

推荐答案

亲爱的您正在尝试更新在表结构中定义了Primary KeyID字段. Primary key始终是唯一的,不应插入duplicate key,并且您正试图通过已定义为primary key的数据进行更新.

以下是错误的.

Dear you are trying to update the ID field which you had defined Primary Key in you table structure. Primary key is always a unique and not supposed to insert a duplicate key and you are forcefully trying to update through a data which is already defined as a primary key.

Following is wrong.

delcmd.CommandText = "UPDATE AddEvent SET ID=" + grdEvents.SelectedRows[0].Cells[0].Value.ToString()+ "";



谢谢
Ashish



Thanks
Ashish


如果有帮助,请参见以下链接:
http://sqlite.phxsoftware.com/forums/t/1418.aspx [ ^ ]
See below link if it helps:
http://sqlite.phxsoftware.com/forums/t/1418.aspx[^]


darshan_ur ,

您上面提到的问题说明您正在尝试在具有主键约束的列中插入重复的值.

检查您要传递以插入作为ID的值,该值不能是全部重复的n.

希望这会有所帮助.

快乐编码:)
Hi darshan_ur,

The problem you stated above explains that you''re trying to insert a duplicate value in the column which has a constraint of being Primary Key.

Check the value which you''re passing to insert as ID, it must not be a duplicate n that''s all.

Hope this helps.

Happy Coding :)


这篇关于由于违反约束而中止PRIMARY KEY必须是唯一的..错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆