TableAdapter.update method, where did it go?

I created a ListBox with your standard smart-control function and connected it to the database. It gets the data I previously created there via the query builder, so when I do this:

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

      

I am getting a list 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 am losing 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 see no reason why the same filling does not have an update method.

+2


source to share


1 answer


You can take a look at the TableAdapter Overview , which says:

If the main query contains information, InsertCommand, UpdateCommand, and DeleteCommand are generated by default when the TableAdapter is created. If the main TableAdapter query is larger than a SELECT statement for a single table, the developer might not be able to generate InsertCommand, UpdateCommand, and DeleteCommand. If these commands are not generated, you may receive an error when you execute the TableAdapter.Update method.

You have two options:

  • Change the main query
  • Modify UpdateCommand.

To change the UpdateCommand, find out what is the class name generated for the TableAdapter. The code should look something like this:




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

      


UPDATE:

As commentators point out, there are other conditions for which commands cannot be generated. See comments.

+6


source







All Articles