使用 DataAdapter .Update 在数据集中插入/更新行(不基于 DB PK)问题

发布于 2024-07-08 12:01:47 字数 473 浏览 12 评论 0原文

我有一个批处理过程,可以根据公共键将多个表中的数据读取到数据集中。 然后,我构建基于同一键查询的目标数据的第二个数据集。

此时,我有两个结构相同的数据集(从表/列布局的角度来看)。 然后,我有一个过程将源中存在的任何行添加到目标数据集中。 此外,该过程还将尝试根据公共密钥更新某些列。

当使用需要更新的现有行调用 DataAdapter.UPDATE 命令时,似乎会出现问题。 错误: System.InvalidOperationException 未处理 Message="SELECT 语句中指定的表不包含唯一键或标识符列,或者 SELECT 语句不包含所有键列。"

由于我无法控制目标数据库上的 PK,是否有办法告诉适配器此特定更新的密钥是什么? 我已“自定义”设置数据集中每个数据表的主键。

这是一个非用户界面的批处理过程,其性能要求相当低。 (解释数据集的使用等)

有什么想法吗?

I have a batch process that reads data from multiple tables into a dataset based on a common key. I then build a second dataset of the destination data querying on the same key.

At this point I have two Datasets that are structurally identical (from a table/column layout perspective). I then have a process that adds any row that exists in source to the destination dataset. In addition, the process will attempt to update certain columns based on the common key as well.

The problem seems to come in when the DataAdapter.UPDATE command is called with existing rows that it needs to update.
Error:
System.InvalidOperationException was unhandled
Message="The table specified in the SELECT statement does not contain a unique key or identifier column, or the SELECT statement does not include all of the key columns."

Since I have no way of controlling what the PK is on the destination DB, is there a way to tell the Adapter what the key is for this particular update? I have "custom" set the primary keys for each DataTable in the Dataset.

This is a non user interfacing batch process and its perf requirements are quite low. (to explain the use of datasets, etc)

Any Thoughts?

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

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

发布评论

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

评论(2

无所的.畏惧 2024-07-15 12:01:47

分析数据库并查看正在触发哪些查询。 从 Profiler 复制查询并尝试手动执行它们。 如果失败,则问题出在 sql 上,错误来自数据库并简单地传递到您的应用程序。

这至少应该告诉你问题是否是由于数据库中缺乏真正的 PK 引起的。

profile the db and see what queries are being fired. copy the queries from Profiler and try to exe them manually. if they fail, then the problem is with the sql and the error is coming from the db and simply being passed up to your application.

this should at least tell u if the problem is caused by the lack of real PK's in the db.

寄意 2024-07-15 12:01:47

您必须像您一样为数据集中的每个表设置 PK。
我不认为适配器有办法自己弄清楚 PK 是什么。
如果有并且有人知道的话我会洗耳恭听。

you have to set the PK for each table in the dataset like you did.
i don't think there's a way for adapter to figure out what the PK's are by itself.
if there is and someone knows it i'm all ears.

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