SqlCommandBuilder 和 SQL Server 计算列 - 错误

发布于 2024-07-23 08:34:27 字数 439 浏览 5 评论 0原文

当用于 SELECT 的 SQL 语句将计算列作为返回字段之一时,避免使用 SqlDataAdapter/SqlCommandbuilder 进行 INSERT 和 UPDATES 时出现错误的正确方法是什么?

我现在收到错误“无法修改列 Amount,因为它要么是计算列,要么是 UNION 运算符的结果”。

更新: 我通过使用如下查询解决了这个问题:

SELECT *, PercentRating * 500 AS CoreValue FROM ValueListings

并放弃计算列。 现在可以了。 SqlCommandBuilder 如何实现将 CoreValue 字段构建到 UPDATE 和 INSERT 语句中? 有人知道这内部是如何运作的吗?

What is the right way to avoid errors on INSERT and UPDATES with a SqlDataAdapter/SqlCommandbuilder when the SQL Statement used to SELECT has a computed column as one of the return fields?

I get the error now that "The column Amount cannot be modified because it is either a computed column or is the result of a UNION operator".

UPDATE:
I fixed the issue by using a query like this:

SELECT *, PercentRating * 500 AS CoreValue FROM ValueListings

And ditching the computed column.
Now it works. How is that SqlCommandBuilder realizes to NOT build the CoreValue field into the UPDATE and INSERT statements? Anybody know how this works internally?

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

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

发布评论

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

评论(2

抚笙 2024-07-30 08:34:27

使用句子:

SELECT * FROM ValueListings

然后填充数据表后,向其中添加计算列:

  Dim Dt as new DataTable
  Da.Fill(Dt)
  Dt.columns.add("CoreValue", GetType(Double), "PercentRating * 500")

Use The Sentence:

SELECT * FROM ValueListings

Then After Fill the DataTable, add a Computed Column to it:

  Dim Dt as new DataTable
  Da.Fill(Dt)
  Dt.columns.add("CoreValue", GetType(Double), "PercentRating * 500")
画离情绘悲伤 2024-07-30 08:34:27

如果您可以避免使用 * ,它将为您省去以后的麻烦。 如果您更改架构,则使用 * 可能会破坏您的代码。 如果命名字段,那就好了。

If you can avoid using the * it WILL save you trouble later. With * if you change the schema your code may break. If named fields, you're good.

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