i’m trying to update my data in datagridview by going to sqldatasource properties “update queries” and writing the codes but its showing an error message
“Violation of PRIMARY KEY constraint ‘PK_contact_master’. Cannot insert duplicate key in object ‘dbo.admission_table’.
The statement has been terminated. “
plz tell me the exact code of editing the data in datagridview and update it..
Thanks,
Churchill
UPDATE:
Sql Code:
Update admission_table
set registration_id=@registration_id,
name_of_degree=@name_of_degree,
fees_paid=@fees_paid,
hostel=@hostel,
hostel_fees=@hostel_fees,
name_of_student=@name_of_student,
Date_of_birth=@Date_of_birth,
nationality=@nationality,
gender=@gender,
address=@address,
phone_no=@phone_no,
e_mail=@e_mail,
date=@date
Based on the sql query you provided it seems like your issue is that you don’t have a where clause on your update query and you appear to be setting the primary key in the update.
This means you will update every record in the table with the same info and violate the PK.
To fix this I would first add a where clause. Once you are updating only the record you want you can most likely remove the
registration_idfrom your set clause (assuming that’s your pk).