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) 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" ); MessageBox.Show( " Please select any record to update" ); catch (Exception ex) MessageBox.Show(ex.Message); 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()+ " " ;
Thanks
Ashish 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 :)
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •