Reputation: 393
I have the following code which (according to a guide) should insert a record into my strongly typed dataset and in turn my database. However, the record is not entered into the database but is correctly entered into the dataset. Am I missing a command?
using (Dataset1TableAdapters.AddressTableAdapter addressAdapter = new Dataset1TableAdapters.AddressTableAdapter())
{
using (Dataset1.AddressDataTable addresses = new Dataset1.AddressDataTable())
{
// Create a new address.
Dataset1.AddressRow address = addresses.NewAddressRow();
// Set some data.
address.Address1 = "test1";
address.Address2 = "test2";
address.Address3 = "test3";
address.UserID = 1;
// Add new address to address table.
addresses.AddAddressRow(address);
// Update the database with all the changes.
addressAdapter.Update(addresses);
}
}
Cheers, Paul.
Upvotes: 2
Views: 1650
Reputation: 11
Please call addresses.AcceptChanges()
before calling update command and let me know if this does not work.
Upvotes: 1
Reputation: 11
I think you need a CommandBuilder
Object associates with your adapter
Upvotes: 1
Reputation: 10399
Is your connection object set correctly? A typed dataset will default its connection based upon configuration. You can also specify a connection object upon creation of a TableAdapter.
Upvotes: 0