Finalizing edits in DataSet when using Bound controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a DataTable within a DataSet which has controls on a WindowsForm bound
to the columns. Of course, I navigate the table with a CurrencyManager. I
have found that unless I call the CurrencyManager's .EndCurrentEdit function
before I call the DataAdapter's .Update, the changes never make it back to
the SQL Server.

Am I doing something wrong? I assumed that when a control was bound to a
field, the changes that are made in the control immediately effect the data
in the underlying table. Do I need to call some special function to finalize
the edit before I Update? I never had to do this before when working with a
DataGrid.

Thanks
 
Is this one just the current record being edited? If not then there's a
problem because when you go to a new record the edit on the previous one
should be finished. Conceptually it may seem a little counterintuitive but
it actually makes quite a bit of sense. Let's say that this behavior wasn't
there and you went in to a field, changed it, realized you screwed something
up and wanted to undo it. Having state availbable allows you to simply call
a method like CancelCurrentEdit and undo everything that had been done.
From a UI perspecitve, lets say you bound to a Dataview for instance that
was sorted on the column you were editing. And you change Ryan to Jones.
Would you really want the position of everything to shift as soon as you
changed the R to a J? By using this model you can signify that the edit is
done and that's it's good (or in the case that it's bad to simply ignore it)
and then the view could go ahead and sort on the entire name in this
example.

I'd encourage you to trap a few events - grap the OnRowChanging Event of the
datatable as well as OnColumnChanging Event. This will give you a feel for
the sequencing of things. Trap the CurrentChanged Event of your
BindingManageBase as well.
 
Actually it seems to occur only on the row I'm editing. Is there a way to
finish the edit on that row just before the Update? Why doesn't the Update
automatically finish the edits.

Thanks for the perspective on the interface.

Michael
 
Hi Michael,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that your last edit was not submitted to the
data source. If there is any misunderstanding, please feel free to let me
know.

To finish editing before updating, the only way seems to be calling
EndCurrentEdit before calling DataAdapter.Update. Since Update method
updates data from the DataSet to database, it knows nothing about the
binding relationship between DataSet and controls. So we have to call
EndCurrentEdit explicitly.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
You're welcome, Michael.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top