none
Not writing DataSet data to physical table??? RRS feed

  • Question

  • I have a typed Expenditure DataSet and have defined a DataRow transDataRow
    as transDataRow = dataSet.Transaction.NewRow(); for my Transaction table.

    I fill the transDataRow with data and Add(transDataRow) then AcceptChanges but
    the data is not being written to the physical table.

    private void btnAddTransaction_Click(object sender, EventArgs e)
            {
                transDate = dttmpickTransDate.Value;
                transDataRow["T_Date"] = transDate;
                transDataRow["T_PayeeId"] = thePayeeId;
                transDataRow["T_Category"] = theCatId;
                transDataRow["T_SubCategory"] = theSubCatId;
                transDataRow["T_PayMethod"] = thePayMethod;
                transDataRow["T_Amount"] = transAmount;
                dataSet.Transaction.Rows.Add(transDataRow);
                dataSet.Transaction.AcceptChanges(); // doesn't write to physical table???
            }

    What am I missing?

    Thanks
    Friday, November 7, 2008 4:24 AM

Answers

  • OK, figured it out:

    ExpenditureTableAdapters.TransactionTableAdapter transDAdapt =
              new ExpenditureTableAdapters.TransactionTableAdapter();

    then

    transDAdapt.Update(dataSet.Transaction);
    Sunday, November 9, 2008 2:13 AM

All replies

  • You should call Update method on SQlDataAdapter before calling AcceptChanges(). AcceptChanges() does not save data itself, it just changes rowstate.
    Friday, November 7, 2008 8:22 AM
  • Given that I am using a typed dataset and my transDataRow refers to a dataset defined thus in my Form Load event:

                     new ExpenditureTableAdapters.TransactionTableAdapter().Fill(dataSet.Transaction);

    how do I call a DataAdapter? I can't see any Intellisense entries for the Update method.
    Saturday, November 8, 2008 11:16 PM
  • OK, figured it out:

    ExpenditureTableAdapters.TransactionTableAdapter transDAdapt =
              new ExpenditureTableAdapters.TransactionTableAdapter();

    then

    transDAdapt.Update(dataSet.Transaction);
    Sunday, November 9, 2008 2:13 AM