如何使用 DataSet(C# 和 MySQL)对没有主键的数据库进行更新

发布于 2024-09-28 14:54:35 字数 220 浏览 0 评论 0原文

我正在使用 C# 和 MySQL 开发 Windows 应用程序。 我通过将文本文件读取到 MySQL 数据库中来插入新记录,该数据库没有主键,但我们可以将四列的组合视为主键的组成部分(但实际上数据库没有主键)。 我知道如何使用 DataAdapter 和 DataSet 添加和更新记录。但我无法更新数据库中没有主键的记录。

您能否指导我,如何使用没有主键的数据库更新数据库中的记录。

谢谢。

I am working on windows application using c# and MySQL.
I inserted new record by reading text file into MySQL database, Database having no primary key but combination of four columns we can consider as component of primary key (but actually database having no primary key).
I know how to add and update record using DataAdapter and DataSet. But I can not update a record in the database having no primary key.

Can you please guide me, how can I update a record in the database with a database having no primary key.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最单纯的乌龟 2024-10-05 14:54:35

假设您有下一个表:

column1,
column2,
..
columnN,
target -- column to update

然后使用:

UPDATE table
SET
   target = @target
WHERE
   column1 = @va1, column2 = @val, -- etc specify all columns in table

如果您有重复(绝对相等)的记录,则将更新所有记录。

Assuming you have next table:

column1,
column2,
..
columnN,
target -- column to update

then use:

UPDATE table
SET
   target = @target
WHERE
   column1 = @va1, column2 = @val, -- etc specify all columns in table

If you have duplicated (absolute equal) records, you will update all of them.

贱贱哒 2024-10-05 14:54:35

为了使其与数据集一起使用,您需要“手动”定义更新命令。

您需要设置正确的DataAdapter.UpdateCommand

在我看来,将主键列添加到表中将是更好的方法。

For this to work with a Dataset you need to define your update command "By-Hand".

You need to set the proper DataAdapter.UpdateCommand.

In my point of view it would be a better approach to just add a primary key column to the table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文