Yogesh Vedpathak

Yogesh Vedpathak

  • 675
  • 1.4k
  • 191.9k

Exception Violation of PRIMARY KEY constraint 'PK_tbl_LineSt

Apr 24 2018 7:36 AM
Violation of PRIMARY KEY constraint 'PK_tbl_LineStatus1'. Cannot insert duplicate key in object 'dbo.tbl_LineStatus1'.
 
The statement has been terminated.
 
This is my Piece of code
  1. using (sqlTrans = sqlCon.BeginTransaction("Trans"))  
  2. {  
  3. try  
  4. {  
  5. string query = "Insert into tbl_LineStatus1(TransID,Date,LineID,UserID) Values('" + TransID + "','" + DateTime.Now.ToString("dd/MM/yyyy") + "','" + ddl_linenumber.SelectedItem.Value.ToString() + "','" + username.ToString() + "')";  
  6. sqlCmd = new SqlCommand(query, sqlCon);  
  7. sqlCmd.Transaction = sqlTrans;  
  8. sqlCmd.ExecuteNonQuery();  
  9. }  
  10. catch(Exception ex)  
  11. {  
  12. }  

Answers (3)