views:

304

answers:

1

Here is my function:

    private void btnSave_Click(object sender, EventArgs e)
    {
        wO_FlangeMillBundlesTableAdapter.Update(invClerkDataDataSet.WO_FlangeMillBundles);
        wO_HeadMillBundlesTableAdapter.Update(invClerkDataDataSet.WO_HeadMillBundles);
        wO_WebMillBundlesTableAdapter.Update(invClerkDataDataSet.WO_WebMillBundles);
        int rowsaffected = wO_MillTableAdapter.Update(invClerkDataDataSet.WO_Mill);

        MessageBox.Show(invClerkDataDataSet.WO_Mill.Rows[0]["GasReading"].ToString());
        MessageBox.Show(rowsaffected.ToString());
    }

You can see the fourth update in the function uses the same functionality as the rest, I just have some debugging stuff added. The first three tables are bound to DataGridViews and work fine. The fourth table has its members bound to various text boxes.

When I change the value in the text box bound to the GasReading column and click save the first MessageBox does in fact show the new value, so it's making it into the dataset correctly. However, the rowsaffected is always showing 0 and the value in the actual database is not being updated.

Can anyone see my problem? I understand that the problem must be elsewhere in my code since the four update methods are the same, but I just don't know where to start.

Here is my binding code:

        txtHours.DataBindings.Add("Text", invClerkDataDataSet.WO_Mill, "HoursRun");
        txtGasReading.DataBindings.Add("Text", invClerkDataDataSet.WO_Mill, "GasReading");
        txtDelayMins.DataBindings.Add("Text", invClerkDataDataSet.WO_Mill, "DelayMins");
        txtGapMins.DataBindings.Add("Text", invClerkDataDataSet.WO_Mill, "GapMins");

I understand there are more elaborate ways to bind, but the binding isn't the issue. Again, data is making it from the bound textboxes into the datatable, but they aren't making it from there to the database.

+2  A: 
  1. It is a good idea to call wO_MillDataSource.EndEdit() before Adapter.Update(). To pull in all changes from the controls.

  2. If there are Foreign Key relations between the 4th table and one of the others you will have to split up Insert/Update and Delete actions, or use a TableAdaptermanager

Henk Holterman
1. I can't find anything like that.2. There are no Foreign Key relations.
Wesley
Ah, I found it, thank you. I had to call .EndEdit() on the row in the datatable.
Wesley
@Wesley: You probably should use BindingSource(s) to link controls to tables. Makes life easier.
Henk Holterman