TableAdapter.update方法,到哪里去了?

发布于 2024-08-04 09:21:26 字数 634 浏览 1 评论 0原文

我用你的标准智能控制东西制作了一个列表框,并将其连接到数据库。它获取我通过查询生成器预先生成的数据,所以当我这样做时:

this.calibrate_swipesTableAdapter.Fill(this.xperdex_crandallDataSet.calibrate_swipes);

我得到一个包含我的数据的列表框。

然后,当我向其中添加一大块数据时,通过以下方式:

toadd["card_number"] = card_number;
this.xperdex_crandallDataSet.Tables["calibrate_swipes"].Rows.Add(toadd);

它也可以工作。效果很好。现在,当我关闭时,我会丢失所有信息。更新我的适配器和 AcceptChanges,对吗?

没那么快。当我打电话时

this.calibrate_swipesTableAdapter.Update(this.xperdex_crandallDataSet.calibrate_swipes);

,我得到“不包含‘更新’的定义”。

什么给?我不明白为什么执行填充的同一件事没有更新方法。

I made a ListBox with your standard smart-control thing, and have it connected to a database. It gets the data I've pre-generated in there via query builder, so when I do this:

this.calibrate_swipesTableAdapter.Fill(this.xperdex_crandallDataSet.calibrate_swipes);

I get a listbox with my data.

THEN, when I add a chunk of data to it, via this:

toadd["card_number"] = card_number;
this.xperdex_crandallDataSet.Tables["calibrate_swipes"].Rows.Add(toadd);

It also works. It works great. Now, when I close, I lose all my information. Update my adapter and AcceptChanges, right?

Not so fast. When I call

this.calibrate_swipesTableAdapter.Update(this.xperdex_crandallDataSet.calibrate_swipes);

I get "does not contain a definition for 'update'".

What gives? I don't see any reason why the same thing that does the filling, wouldn't have an update method.

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

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

发布评论

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

评论(1

抚笙 2024-08-11 09:21:26

您可能需要查看TableAdapter 概述其中指出:

如果主查询中有足够的信息,则在生成TableAdapter时默认创建InsertCommand、UpdateCommand和DeleteCommand命令。 如果TableAdapter的主查询是多个表SELECT语句,则设计者可能无法生成InsertCommand、UpdateCommand和DeleteCommand。如果未生成这些命令,则在执行 TableAdapter.Update 方法时可能会收到错误。

您有两个选择:

  • 更改主查询
  • 更改 UpdateCommand。

要更改 UpdateCommand,请找出为 TableAdapter 生成的类的名称。代码应如下所示:


SqlCommand yourUpdateCommand = new SqlCommand("UPDATE...", connection);
this.calibrate_swipesTableAdapter.Adapter.UpdateCommand = yourUpdateCommand;

更新:

正如评论者所说,还有其他情况可能无法生成命令。 查看评论。

You may want to take a look at TableAdapter Overview which states:

If there is enough information in the main query, the InsertCommand, UpdateCommand, and DeleteCommand commands are created by default when the TableAdapter is generated. If the TableAdapter's main query is more than a single table SELECT statement, it is possible the designer will not be able to generate the InsertCommand, UpdateCommand, and DeleteCommand. If these commands are not generated, you may receive an error when executing the TableAdapter.Update method.

You have two choices:

  • Change your main query
  • Change the UpdateCommand.

To change the UpdateCommand, find out what's the name of the class generated for the TableAdapter. The code should look something like the following:


SqlCommand yourUpdateCommand = new SqlCommand("UPDATE...", connection);
this.calibrate_swipesTableAdapter.Adapter.UpdateCommand = yourUpdateCommand;

UPDATE:

As commenters said, there are other conditions for which the commands may not be generated. See the comments.

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