What happened to my TableAdapter's Update and Delete commands?
Asked Answered
E

5

6

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

Eboh answered 5/6, 2009 at 16:46 Comment(1)
From the total lack of comments, I take it this hasn't happened to anyone else, so I have a true bug or glitch in my VS2008 implementation. Great. And I got a frickin' tumbleweed badge for the privilege as well.Eboh
I
14

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

Itagaki answered 29/7, 2009 at 12:3 Comment(1)
Dont feel to crappy about it, I just did the same thing :( Setting the PK in the DB fixed the same issue for me.Cashbook
D
0

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!

Diann answered 29/7, 2009 at 22:11 Comment(1)
Thanks for the link to the article. However, my problem (and maybe yours, as well) is simpler than that. All I had to do was define primary keys and a relationship in the SQL Studio designer, and VS liked it just fine. I don't know what your data looks like, but VS can get quite a bit of info from SQL Server -- or not, apparently.Eboh
D
0

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

Diann answered 30/7, 2009 at 15:37 Comment(2)
Too much work! :) That's essentially what I did do to get it working. However, it worked a lot slicker and cleaner, without manually changing anything, when I defined primary keys and relations in the database -- VS2008 figured out how to do what it needed to do from that information, with no manual intervention...Eboh
You got this solution to work for MS Access? I'm having this exact issue and I'm trying to get your method to work.Recessive
A
0

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.

Agram answered 26/8, 2009 at 21:9 Comment(0)
O
0

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.

Oulman answered 15/7, 2014 at 2:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.