无法更新数据库主键列 [英] cannot update database primary key column

查看:233
本文介绍了无法更新数据库主键列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,该文本框从数据库返回一个值,该值也是我的主键列,因此我从company那里获取了它的值,这是我的主键,然后在我按Enter键时在文本框中更新了值

I have a textbox that returns a value from a database this value is also my primary key column so i get the value from company which is my primary key i then update the value in the textbox when i press enter i run

("UPDATE t_company SET Company_Name=@Company_Name where Company_Name=@Company_Name",mycon1)


问题是它不会给我任何错误,但不会在数据库中更新它,但是如果我将@company的值更改为固定值


the problem is it doesnt give me any errors but it does not update it in the database but if i change the value of @company to a fixed value

("UPDATE t_company SET Company_Name=@Company_Name where Company_Name='abc'",mycon1)

然后可以运行
任何帮助将不胜感激.

it then works
any help would be appreciated.

推荐答案

在您之前的查询中,您没有更新任何内容.

查看您的查询
In your previous query you are not updating anything.

See your query
UPDATE t_company SET Company_Name=@Company_Name where Company_Name=@Company_Name



这意味着您正在使用相同的值更新公司名称.因此,您没有观察到更改.



It means you are updating Company name with the same value. Hence you are not observing change.


u也应设置公司主键
更新查询将更新您仅指定了哪一列
您没有提到要更新的主键列名称

u should set company primary key too
update query will update which column u specified only
u didn''t mentioned the primary key column name to update

("UPDATE t_company SET Company_Id=@Company_Id,Company_Name=@Company_Name where Company_Name=@Company_Name",mycon1)


这篇关于无法更新数据库主键列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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