Ai47
Ai47

Reputation: 41

Saving new Data to a Data Set

I have searched and searched.

My application uses a database created with SQL Server Compact Edition.

How can I save data (add new rows only) to the actual database using my application.

Would I insert the code into the saveButton?

    private void saveToolStripMenuItem_Click(obeject sender, EventArgs e)
    {
      EcoDataSet edata = new EcoDataSet();

      EcoDataSetTableAdapters.CustomersTableAdapter cTA =
      new EcoDataSetTableAdapters.CustomersTableAdapter();

      cTA.Fill(edata.Customers);
      cTA.Update(eco.Customers);
    }

Will that do the trick or should I add a TextChanged event to my DataGridView?

Upvotes: 2

Views: 57

Answers (1)

John Saunders
John Saunders

Reputation: 161773

Update only updates changed rows. You aren't writing anything because you're using two different DataSet objects.

You need to apply the rows in eco.Customers to edata.Customers, then do the Update.

You should be able to use DataTable.Merge to apply the changes.

Upvotes: 1

Related Questions