这些 .NET 自动生成的表适配器命令有什么作用?例如 UPDATE/INSERT 后跟 SELECT

发布于 2024-08-28 11:18:13 字数 587 浏览 6 评论 0原文

我正在使用一个遗留应用程序,我试图对其进行更改,以便它可以与 SQL CE 一起使用,而它最初是针对 SQL Server 编写的。

我现在遇到的问题是,当我尝试执行 dataAdapter.Update 时,SQL CE 抱怨它不期望命令文本中出现 SELECT 关键字。我相信这是因为 SQL CE 不支持批量 SELECT 语句。

自动生成的表适配器命令如下所示...

this._adapter.InsertCommand.CommandText = @"INSERT INTO [Table] ([Field1], [Field2]) VALUES (@Value1, @Value2);
SELECT Field1, Field2 FROM Table WHERE (Field1 = @Value1)";

它在做什么?看起来它正在将数据表中的新记录插入数据库,然后将该记录从数据库读回到数据表中?那有什么意义呢?

我可以浏览一下代码并删除所有这些 SELECT 语句吗?或者有没有更简单的方法来解决我想要将这些数据适配器与 SQL CE 一起使用的问题?

我无法重新生成这些表适配器,因为知道如何操作的人早已离开。

I'm working with a legacy application which I'm trying to change so that it can work with SQL CE, whilst it was originally written against SQL Server.

The problem I am getting now is that when I try to do dataAdapter.Update, SQL CE complains that it is not expecting the SELECT keyword in the command text. I believe this is because SQL CE does not support batch SELECT statements.

The auto-generated table adapter command looks like this...

this._adapter.InsertCommand.CommandText = @"INSERT INTO [Table] ([Field1], [Field2]) VALUES (@Value1, @Value2);
SELECT Field1, Field2 FROM Table WHERE (Field1 = @Value1)";

What is it doing? It looks like it is inserting new records from the datatable into the database, and then reading that record back from the database into the datatable? What's the point of that?

Can I just go through the code and remove all these SELECT statements? Or is there an easier way to solve my problem of wanting to use these data adapters with SQL CE?

I cannot regenerate these table adapters, as the people who knew how to have long since left.

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

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

发布评论

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

评论(2

笑红尘 2024-09-04 11:18:14

它只是在更新后使用数据库中的最新值更新对象。对我来说总是有点不必要,但是嘿......

从维护的角度来看,这些都是令人讨厌的 - 如果您有选择,您可以通过将所有这些抽象到适当的数据层来为自己省去很多麻烦。

It is just updating the object with the latest values from the database, after an update. Always seemed a little unecessary to me but hey...

These are a nuisance from a maintenance point of view - if you have the option, you'll save yourself a lot of hassle by abstracting this all out to a proper data layer.

墟烟 2024-09-04 11:18:14

允许表上的触发器更改字段值。我想,在自动生成的样板文件中,这已经足够明智了。

虽然 select 语句假设 field1 是主键有点奇怪......但也许 autogen 代码在生成这段代码之前确保它是主键。

allows that the field values might be altered by trigger(s) on the table. Sensible enough, I'd have thought, in auto-generated boilerplate.

though the select statement is a tad whacky to assume that field1 is the primary key... but maybe the autogen code makes sure it is before generating this bit of code.

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