views:

838

answers:

1

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.

+2  A: 

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.

Alfred Myers
+1 Can also happen if the table is not updatable, due to a key problem (no key, non unique key...)
Pierre-Alain Vigeant
If you don't have primary key, designer won't generate update,delete and insert methods for adapter.
Braveyard
Thank you guys. I updated the answer.
Alfred Myers
I do have a primary key to it, so I don't know why it wouldn't have generated update methods to the table... but... I didn't have the update method there. So....
David