Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone here is my code but i keep getting the following error
XML
Duplicate entry 'ACSA-b-a' for key 'PRIMARY'<pre lang="sql">MySqlCommand sqlcom = new MySqlCommand(&quot;UPDATE t_groups SET Groups=@Groups,Description=@Description,Shared=@Shared  where User_Name =&#39;&quot; + userName + &quot;&#39;and Company_Name=&#39;&quot; + CompanyName + &quot;&#39;&quot;, mycon1);
            sqlcom.Parameters.Add(&quot;@Company_Name&quot;, MySqlDbType.VarChar, 100).Value = lblEditcompany.Text;
            sqlcom.Parameters.Add(&quot;@User_Name&quot;, MySqlDbType.VarChar, 100).Value = lblEditUserName.Text;
            sqlcom.Parameters.Add(&quot;@Groups&quot;, MySqlDbType.VarChar, 100).Value = txtEditGroup.Text;
            sqlcom.Parameters.Add(&quot;@Description&quot;, MySqlDbType.VarChar, 100).Value = txtEditDescription.Text;
            sqlcom.Parameters.Add(&quot;@Shared&quot;, MySqlDbType.VarChar, 100).Value = DDEditShared.SelectedValue;

            this.ModalPopupExtenderEditGroup.Hide();
            sqlcom.ExecuteNonQuery();</pre>



the value of Company_Name = Acsa and the value of user_Name = b and the value of Groups is a i am only updating the value of description
my table has three keys Company_Name,User_Name ,groups please help me i can insert and delete fine but its my update that breaks
Posted

1 solution

If you are getting a "Duplicate Entry" error, then you have a problem with the data you are feeding in.
I think your issue is in the way you define your primary key on your table. Why on earth would you include groups in your primary key?
If you remove the Groups column from your primary key your query will work.
 
Share this answer
 
Comments
mrDivan 31-Oct-12 10:12am    
Hi marcus my other table depends on it to be a primary key the group table has 5 columns company_Name pk,user_Name pk,groups pk, description,shared
the table has many to many relationship to my other table which has the following columns company_Name pk user_Name pk,groups pk, cellNo pk ,title,name ,ref
the 1 table has foreign key relationships to the first tables primary keys
fjdiewornncalwe 31-Oct-12 10:33am    
It appears that you have a serious issue with the normalization of your database which is going to make things difficult for you. If you find yourself repeating multiple similar columns in different tables, then you are not normalized. The primary tables should be assigned an id with a unique constraint added to the applicable other columns so that you only need to have the primary id referenced from tables that need it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900