本文介绍了由于违反约束而中止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);
}
}
推荐答案
delcmd.CommandText = "UPDATE AddEvent SET ID=" + grdEvents.SelectedRows[0].Cells[0].Value.ToString()+ "";
谢谢
Ashish
Thanks
Ashish
这篇关于由于违反约束而中止PRIMARY KEY必须是唯一的..错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!