Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dataset changes not being written to database

Status
Not open for further replies.

misterstick

Programmer
Joined
Apr 7, 2000
Messages
633
Location
GB
i have a form linked to an oracle database via System.Data.OracleClient.

it uses form designer level Connection -> DataAdapter -> DataSet objects.

the DataAdapter has all default SIUD objects.

TextBox objects are bound to DataTable.DataColumns in the DataSet object.

currency is managed by a CurrencyManager.


everything works pretty much as i want except for one thing.


if i make changes to the data i can see that the data has a new value in DataSet.DATATABLE[Row].Column.

just before update, though, DataSet.DATATABLE.HasChanges is false and DataSet.DATATABLE.GetChanges is null.

calls to DataSet.DATATABLE.AcceptChanges and DataAdapter.Update don't write records back to the database.


what should i be investigating? i can't think beyond the fact that i've made changes to the DataSet, so HasChanges should be true.

i haven't changed CurrencyManager.Position to go to a new record, so what could be resetting the changes?

yours completely stumped,


mr s. <;)

 
further, i am baffled by the following code:

Code:
DataSet.DATATABLE[Row].BeginEdit();

MessageBox.Show(this, DataSet.HasChanges().ToString()); // [COLOR=blue]False[/color]

MessageBox.Show(this, DataSet.DATATABLE[Row].COLUMN.ToString()); // [COLOR=blue]"oldvalue"[/color]

DataSet.DATATABLE[Row].COLUMN = "newvalue";

MessageBox.Show(this, DataSet.DATATABLE[Row].COLUMN.ToString()); // [COLOR=blue]"newvalue"[/color]

MessageBox.Show(this, DataSet.HasChanges().ToString()); // [COLOR=blue]false[/color] [COLOR=red](wtf?)[/color]

what is going on here?


mr s. <;)

 
From doc:
<<When you put a row in Edit mode, events are temporarily suspended allowing the user to make multiple changes to more than one row without triggering validation rules. For example, if you need to ensure that the value of the column for a total amount is equal to the values for the debit and credit columns in a row, you can put each of the rows into edit mode to suspend the validation of the row values until the user attempts to commit the values.>>
So, before calling the EndEdit method , you can retrieve either the original or proposed vvalues by checking DataRowVersion.Original or DataRowVersion.Proposed flags for the version parameter of the Item property.
obislavu
 
thanks for that.

while i was waiting, i played about for a while and discovered that i had to end the edit, otherwise the changes aren't visible to the dataset.

which i think is what obislavu's documentation is trying to say.

problem solved by calling DataSet.DATATABLE[Row].EndEdit()

Code:
DataSet.DATATABLE[Row].BeginEdit();

MessageBox.Show(this, DataSet.HasChanges().ToString()); // [COLOR=blue]False[/color]

MessageBox.Show(this, DataSet.DATATABLE[Row].COLUMN.ToString()); // [COLOR=blue]"oldvalue"[/color]

DataSet.DATATABLE[Row].COLUMN = "newvalue";

MessageBox.Show(this, DataSet.DATATABLE[Row].COLUMN.ToString()); // [COLOR=blue]"newvalue"[/color]

MessageBox.Show(this, DataSet.HasChanges().ToString()); // [COLOR=blue]false[/color]

DataSet.DATATABLE[Row].EndEdit();

MessageBox.Show(this, DataSet.HasChanges().ToString()); // [COLOR=blue]true[/color]

many thanks,

mr s. <;)

 
I gave you the reason why the 2nd HasChanges() is false and you have to call EndEdit (or CancelEdit ) in order to take effect.
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top