Reputation: 2993
I am using the C# VS2010 TableAdapter Wizard for my project to interface with my db. I have generated my own Insert, Update and Delete commands for this adapter since it uses a join and can not generate its own. I'm okay with that, but unfortunately when I created the Insert command I am not able to call the "Insert()" method on the tableadapter. The other methods are working fine.
For example,
`this.joinTableAdapter = new MyTableAdapter();
this.joinTableAdapter.Insert() <-- does not exist.`
It was my understanding that once you create a valid insert command that this method should become visible on the table adapter. Am I mistaken about this? It is working for my update and delete command. Any ideas what I am doing wrong?
Any help is appreciated. Thanks everyone!
Upvotes: 1
Views: 8404
Reputation: 1
Go into the dataset click on the tableadaptor and check setting for property "GenerateDBDirectMethods" - Needs to be true
Upvotes: 0
Reputation: 638
There is a 4th way of working with JOIN queries.
For the table adapter's main query, omit the join. Then, add manually the columns to the data table and set their SourceColumn to the exact spelling of the fields you will add. Finally, add a new query to the table adapter that includes the join and call this query to fill the datatables in your application.
If this is too abbreviated, let me know. I'll elaborate more.
Upvotes: 0
Reputation: 460238
TableAdapter GenerateDbDirectMethods
In addition to the InsertCommand, UpdateCommand, and DeleteCommand, TableAdapters are created with methods that can be executed directly against the database. These methods (TableAdapter.Insert, TableAdapter.Update, and TableAdapter.Delete) can be called directly to manipulate data in the database.
If you do not want to create these direct methods, set the TableAdapter's GenerateDbDirectMethods property to false (in the Properties window). Additional queries added to the TableAdapter are standalone queries — they do not generate these methods.
You'll find this option at the designer in the second last page. Create methods to send updates directly to the database
Note: This is not the same then clicking Advanced Options and click:
Generate Insert, Update, and Delete statements
When you select this option, the wizard will attempt to generate INSERT, UPDATE, and DELETE statements based on the SELECT statement defined on the Generate SQL statements page.
Edit:
The TableAdapter cannot create insert,update and delete statements automatically when more than one table is involved in the main select query. There are several approaches if you need one or more columns of related tables, the best way depends on your requirement.
InsertUser(param1,param2)
)Update
. The DataRow's RowState determines which command will be triggered(f.e. Added->InsertCommand).For the third approach you could use LINQ-To-DataSet to join the related tables to get all needed columns(f.e. to create a DataSource for a GridView).
Upvotes: 1