2011-03-21 67 views
0

我試圖通過將SqlDataSource的性質「更新查詢」,寫的代碼,但它顯示錯誤信息來更新我的datagridview的數據修改和更新在數據網格視圖記錄

「主鍵違反約束「PK_contact_master」。不能插入對象「dbo.admission_table」重複鍵。 該語句已終止。「

PLZ告訴我的datagridview編輯數據的準確代碼,並更新它..

謝謝, 丘吉爾

UPDATE:

的SQL代碼:

Update admission_table 
set [email protected]_id, 
[email protected]_of_degree, 
[email protected]_paid, 
[email protected], 
[email protected]_fees, 
[email protected]_of_student, 
Dat­[email protected]_of_birth, 
[email protected], 
[email protected], 
[email protected]­s, 
[email protected]_no, 
[email protected]_mail, 
[email protected] 
+0

告訴我們你現在有什麼代碼,也許我們會。 – 2011-03-21 18:50:45

+0

更新admission_table設置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,國籍= @國籍,性別= @性別,地址= @地址,電話號碼= @電話號碼,e_mail = @電子郵件,日期= @日期 – Churchill 2011-03-21 18:52:40

+1

registration_id列是我的表的主鍵,等於@registration_id是我的表列的名稱 – Churchill 2011-03-21 18:54:39

回答

2

根據您所提供好像你的問題的SQL查詢,你沒有您的更新查詢的WHERE子句,你似乎是在更新中設置主鍵。

這意味着你將用相同的信息更新表格中的每條記錄並違反PK。

要解決這個問題,我會先添加一個where子句。一旦你只更新了你想要的記錄,你很可能會從你的set子句中刪除registration_id(假設這是你的pk)。

+1

好吧,非常感謝你,我有解決了我的問題....並且它的工作非常完美..thank_u – Churchill 2011-03-21 19:05:20