我的 TableAdapter 的更新和删除命令发生了什么?

发布于 2024-07-23 11:05:00 字数 892 浏览 9 评论 0原文

看起来我正在与一个顽固的 VS2008 数据集设计者战斗。 我一直在尝试做一个看似简单的 2 表数据集解决方案,其中一个表只是存储在另一个表中的整数值的文本含义。 基本数据设计 101。

Table1
CharField1
CharField2
IntForeignKeyField1
etc

Table2
IntPrimaryKey1
ValueForKeyField

我不相信,这并没有真正影响我遇到的问题,因为我不想做任何事情,只是从第二个表中读取值,这样我就可以在 DataGridViewComboBoxColumn 中选择它们客户端——我永远不会在客户端上编辑它们。 但是,我离题了。

由于它存在于 Web 服务中,并且我希望将强类型数据集传递给该 Web 服务的客户端,因此我决定使用数据集设计器来构建 TableAdapter 和所有管道,认为这可能会减少工作量并且更容易维持。

因此,我创建了漂亮的框并编辑了 select 语句,指示设计者创建所有插入、更新和删除命令以供表适配器使用。 它很高兴地答应了我,告诉我一切都按照我的要求完成了。

然而,当我尝试使用 Update 语句时,我收到一条错误消息,指出没有有效的 Update 语句! 在网上对有类似问题的人进行了一些徒劳的搜索后,我深入研究了数据集的 XML。 果然,没有Update 语句,也没有Delete 语句。

我尝试从项目中完全删除并重新创建数据集,得到相同的结果。 没有创建任何更新或删除语句,即使它被报告为已完成。

我最终通过检查另一个项目的另一个设计的数据集来手动构建更新语句 XML,因此 Web 服务现在正在运行。 然而,我不相信我的更改会在设计师发起的编辑中持续下去,而且我很困惑为什么它不起作用。 有任何想法吗?

感谢您的任何反馈, 戴夫

I am fighting a recalcitrant VS2008 DataSet designer, it seems. I have been trying to do what seems to be a simple 2-table dataset solution, where one table is simply the textual meaning for an integer value stored in the other table. Basic data design 101.

Table1
CharField1
CharField2
IntForeignKeyField1
etc

Table2
IntPrimaryKey1
ValueForKeyField

That doesn't really affect the problem I am having, I don't believe, as I am not wanting to do anything but read the values in from the second table so I can choose them in a DataGridViewComboBoxColumn in the client -- I will never edit them on the client. But, I digress.

Since this lives in a web service, and I wanted a strongly-typed dataset delivered to the clients of this web service, I decided to use the DataSet Designer to build the TableAdapters and all the plumbing, thinking it might be less work and easier to maintain.

So, I created the pretty boxes and edited the select statements, instructing the designer to create all Insert, Update and Delete commands for the table adapter to use. It happily obliged, informing me that everything was done as I asked.

When I tried to use the Update statement, however, I got an error saying there was no valid Update statement! After some fruitless searching around for people with similar woes on the web, I dug into the XML for the dataset. Sure enough, no Update statement, and no Delete statement, either.

I tried completely deleting and recreating the DataSet from the project, with the same results. No Update or Delete statements were created, even though it was reported as done.

I ended up building the Update statement XML by hand, by inspecting another designed dataset from another project, so the web service is now working. However, I have no faith whatsoever my changes would last through an edit initiated from the designer, and I am stumped as to why it is not working. Any ideas?

Thanks for any feedback,
Dave

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

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

发布评论

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

评论(5

半步萧音过轻尘 2024-07-30 11:05:01

刚刚遇到了同样的基本问题。 我告诉数据设计者创建所有插入、更新、删除语句。 当我去更新其中一张表时,没有可用的更新。 我最终进入了数据设计器创建的 .xsd 文件(只需双击即可在 IDE 中打开它)。 然后,我右键单击出现问题的表的标题栏并选择配置选项。 从那里我单击“高级选项”按钮,然后选择“生成插入、更新、删除语句”选项。 按“确定”后,我检查了我的项目,并且更新可用于表适配器。

Just ran into the same basic problem. I told the data designer to create all insert, update, delete statements. When I went to update one of the tables there was no update available. I finally went into the .xsd file created by the data designer (just double clicked to open it in the IDE). I then right clicked on the title bar of the table that had the issue and selected the configure option. From there I clicked the 'Advanced Options' button, then selected the 'Generate Insert, Update, Delete Statements' option. After pressing Okay I checked my project and the update was available for the table adapter.

空城缀染半城烟沙 2024-07-30 11:05:01

乔治的建议很棒。 我们需要启用“生成插入、更新、删除语句”选项。

然而,在 VS2013 中,在 selete 语句中使用不必要的表限定符可能会扰乱 IDE,并导致仅生成 SELECT 和 INSERT 语句。 只要删除这个限定符就应该没问题了。 确保你也有独特的PK。

如果您需要使用复杂的填充(例如应用过滤器仅返回表的某些行),您可以在表单加载事件中使用特定的 select 语句填充数据表。 这样,生成的 INSERT、UPDATE 和 DELETE 语句仍然有效,因为 DELETE 和 UPDATE 对 PK 起作用。

What George suggested is great. We need to enable the 'Generate Insert, Update, Delete Statements' option.

However in VS2013, using unnecessary table qualifiers in the selete statement may upset the IDE and result in the generation of SELECT and INSERT statements only. Just remove this qualifiers and it should be alright. Make sure you have a unique PK too.

If you need to use complicated fill like applying filter to return certain rows of the table only, you can fill the data table using specific select statement in the form load event. In that way, the generated INSERT, UPDATE and DELETE statements will still work, because DELETE and UPDATE work on the PK.

信愁 2024-07-30 11:05:00

难道是表没有定义唯一主键?

could it be that there is no unique primary key defined for the table?

思念绕指尖 2024-07-30 11:05:00

我有同样的问题。 当使用多个表中的字段时,TableAdapter 无法正常工作。 我能够从以下文章中重新创建解决方案:“更新 TableAdapter 以使用联接”。

http://www.asp.net/learn/data- access/tutorial-69-vb.aspx

该解决方案涉及创建您自己的选择/更新/插入/删除过程。 不幸的是,虽然我能够遵循 sqlserver 数据库的解决方案,但我仍然无法让它适用于我的本地 Access 数据库。 所有存储过程选项均呈灰色。

祝你好运!

I am having the same problem. The TableAdapter does not work properly when using fields from more than one table. I was able to re-create the solution from the following article: "Updating the TableAdapter to Use Joins".

http://www.asp.net/learn/data-access/tutorial-69-vb.aspx

The solution involves creating your own Select/Update/Insert/Delete procedures. Unfortunately, while I was able to follow the solution for an sqlserver database, I am still not able to get it to work for my local Access database. All the stored procedure options are grayed out.

Good Luck!

画离情绘悲伤 2024-07-30 11:05:00

我想我找到了解决方案。
1)仅为主表创建一个TableAdapter并复制TableAdapter UPDATE过程(存储在TableAdapter属性窗口中)
2) 更改“TableAdapter 配置向导查询生成器”中的 SELECT 查询以包括来自表和联接的字段。
3) 将旧的 UPDATE 过程粘贴到现在空白的 TableAdapter UPDATE 过程中。
4)创建DataGridView后,您可以显示两个表中的字段并更新主表。
重复 INSERT & 的步骤 删除命令。

如果您的目标是更新两个表,请尝试在 Web 上查找 TableAdapter 父/子更新信息。
这是一个很好的链接:
http://blogs.msdn.com/bethmassi/archive/2009/05/14/using-tableadapters-to-insert-lated-data-into-an-ms-access-database.aspx< /a>

I think I found the solution.
1) Create a TableAdapter for the main table only and copy the TableAdapter UPDATE procedure (stored in TableAdapter properties window)
2) Change the SELECT query in the"TableAdapter Configuration Wizard Query Builder" to include fields from both tables and the join.
3) Paste the old UPDATE procedure into the now blank TableAdapter UPDATE procedure.
4) After creating DataGridView, you can display fields from both tables and update the main table.
Repeat steps for INSERT & DELETE commands.

If your goal is to update both tables, try looking into TableAdapter Parent/Child update information on the web.
Here is a good link:
http://blogs.msdn.com/bethmassi/archive/2009/05/14/using-tableadapters-to-insert-related-data-into-an-ms-access-database.aspx

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