MySQL更新语句损坏 [英] Mysql update statement broken

查看:76
本文介绍了MySQL更新语句损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,这是我的代码,但我不断收到以下错误

hi everyone here is my code but i keep getting the following error

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>




Company_Name = Acsa的值和user_Name = b的值,Groups的值是a我只是更新description的值
我的表有三个键Company_Name,User_Name,groups请帮助我,我可以插入和删除,但是它的更新会中断




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

推荐答案

如果您收到重复条目" "错误,则说明您输入的数据有问题.
我认为您的问题在于您在表上定义主键的方式.到底为什么要在主键中包含组?
如果您从主键中删除组"列,则查询将起作用.
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.


这篇关于MySQL更新语句损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆