paulio
paulio

Reputation: 393

Strongly typed dataset Adapter.Update not inserting row

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

Answers (3)

Ravi
Ravi

Reputation: 11

Please call addresses.AcceptChanges() before calling update command and let me know if this does not work.

Upvotes: 1

Hoang Thang
Hoang Thang

Reputation: 11

I think you need a CommandBuilder Object associates with your adapter

Upvotes: 1

Matt Brunell
Matt Brunell

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

Related Questions