Why isn't my data adapter updating?

  • Thread starter Thread starter sandman
  • Start date Start date
S

sandman

I've got a simple windows form with some bound textboxes
and Save button. Each texbox is bound to column in a table
in an Access database. The form fills fine - all the
fields show the correct data for the record I load. So
then I change the contents of one of the textboxes and
click on the Save button. The button's event handler then
calls the data adapter's Update method and I check the
return value. Nada-zilch-nothing. I even put a breakpoint
there, dug into the DataSet in the debugger and found the
DataRow in question. Sure enough, there is my changed
data but RowState is showing Unchanged. The documentation
("Introduction to DataSet Updates") says: "In Windows
Forms, the data-binding architecture takes care of sending
changes from data-bound controls to the dataset, and you
do not have to explicitly update the dataset with your own
code." Sounds pretty clear to me but obviously it's not
working the way I think it should. What am I missing??
 
look this tread from the databinding group:



I hope this help...



MP

Stuart Powers said:
I have solved the problem.

the problem was, for a datarow that you're editing, before you edit it you
have to call BeginEdit(), then when all the changes are done, before you
Update() (stick the datatable back in the database) you have to call
EndEdit(). After you update, call AcceptChanges(), which changes tells the
datatable it is synch'd with the database, sorta.

The reason a datagrid was working and not the textbox, i suspect, is because
the datagrid internally takes care of the BeginEdit()/EndEdit() things.

Hope this helps, if not, write back

-Stu

----- Original Message -----
From: "MP" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.windowsforms.databinding
Sent: Monday, August 11, 2003 7:13 PM
Subject: Re: Binding Problem: TextBox vs. DataSet (maybe simple solution?)

Hello



I found this tread a few day ago, is from a Spanish group but I think you
can understand the idea, if you need more translation, tell me.



I have the same problem and the same frustration, but now I'm on other
problem and going to try this solution later.



If you get the solution please let me know, I will do the same when I look
for it



I hope this help.



MP

---------------

from: microsoft.public.es.csharp



Buen esto ocurre por que no se ha terminado la operación de edición actual,
es por eso que desplazar el currency manager tambien funciona, pero, ¿si
existe solo un registro acia donde desplazar =( ?.

'Si la operación de edicion se realiza desde un Datagrid mDataGrid
Me.mGrid.EndEdit(Me.mTableStyle.GridColumnStyles(Me.mGrid.CurrentCell.Column
Number), _

Me.mGrid.CurrentCell.RowNumber, False)

CType(Me.BindingContext(Me.mGrid.DataSource),
CurrencyManager).EndCurrentEdit()

'Si la operación de edicion se realiza a travez de un DataView

CType(Me.BindingContext(Me.mDataView), CurrencyManager).EndCurrentEdit()

'Si la operación de edicion se realiza a travez de un DataTable en un
DataSet

CType(Me.BindingContext(Me.mDataSet.mDataTable),
CurrencyManager).EndCurrentEdit()


Stuart Powers said:
Hello,

This is a /very/ odd problem and any insight would be greatly appreciated.

1) I have used SqlDataAdapter to fill a DataTable in a DataSet.
2) I binded textbox's "Text" property to columns in the DataTable.
3) I edit the textboxes Text value.
in doing so, the DataTable's values have changed
I know this because i have done:
MessageBox.Show(dataTable.Rows[0]["colname"].ToString());
4) I attempt to update the database: myDataAdapter.Update(myDataSet,
"tablename");
this does not work.

now the weird part:

if you replace steps 2 and 3 with:
2) Create a datagrid whose DataSource = myDataSet.Tables["tablename"];
3) make changes in the datagrid

then step will 4 work correctly. (somehow the datagrid must change the
dataset differently than the textboxes do, it appears)
however, this makes no sense, because doing:
MessageBox.Show(dataTable.Rows[0]["colname"].ToString());
prints the same thing with both methods

what is /really/ weird:

Suppose I have both the textboxes and the datagrid, both bound to the
DataTable. When I edit a textbox, then try and update the database, it
sitll doesn't work (as expected, because it didn't work before). However,
If I edit a textbox, then merely click on the datagrid (give it focus) the
value in the datagrid then changes (as if its being refreshed to show the
change I made to the textbox). now, after clicking the datagrid, when I
press try and update the database: myDataAdapter.Update(myDataSet,
"tablename"); it WORKS.

I have have absolutely no idea why merely clicking on the datagrid
makes
 
Back
Top