Strongly typed Adapter.Update dataset without inserting a string

I have the following code, which (according to the guide ) should insert a record into my highly typed dataset and, in turn, my database. However, the record is not entered into the database, but correctly entered into the data set. Am I missing a team?

    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.

+3
source share
3 answers

I think you need CommandBuilderan object associated with your adapter

+1
source

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

+1
source

? , . TableAdapter.

0

Source: https://habr.com/ru/post/1709413/


All Articles