![](/img/trans.png)
[英]How to find primary key column name in C# or dotnet using dataset?
[英]How to update using DataSet (C# and MySQL) with the database with no primary key
我正在使用c#和MySQL处理Windows应用程序。 我通过将文本文件读取到MySQL数据库中来插入新记录,该数据库没有主键,但四列的组合可以视为主键的组成部分(但实际上没有主键的数据库)。 我知道如何使用DataAdapter和DataSet添加和更新记录。 但我无法更新没有主键的数据库中的记录。
能否指导我,如何使用没有主键的数据库更新数据库中的记录。
谢谢。
假设你有下一张桌子:
column1,
column2,
..
columnN,
target -- column to update
然后使用:
UPDATE table
SET
target = @target
WHERE
column1 = @va1, column2 = @val, -- etc specify all columns in table
如果您有重复(绝对相等)记录,您将更新所有记录。
要使用数据集,您需要定义更新命令“By-Hand”。
您需要设置正确的DataAdapter.UpdateCommand
。
以我的观点,将主键列添加到表中将是更好的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.