.Update doesn't save value from a TextBox

thomas10001

Well-known member
Joined
Jun 22, 2003
Messages
57
Location
Samoa & Sweden
I am using C#.Net 2003. Probably it would have the same solution in VB.

I have a oleDbDataAdapter, oleDbConnection and a DataSet.

I attached the dataset to a TextBox to its Text property (under databindings).

When I want to save the value in the textbox using .Update it doesnt save the changes!

(The .Fill works fine to load the data into the textbox. Also if I use a DataGrid instead of a TextBox .Update works fine)

What do I need to do?
 
// code for loading, which works fine
dsPlayer1.Clear();
oleDbDataAdapterPlayer.Fill(dsPlayer1);

// code for saving, which doesnt work
oleDbDataAdapterPlayer.Update(dsPlayer1);
 
If I have a listbox as well connected to the dataset. I can save it if I do exactly this:

1. Select one entry in the listbox
2. enter data in the textbox
3. select another entry in the listbox
4. click on my Save button so my .Update executes

So there is something that get triggered when I select another entry that makes my data being saved. Is there some rowstatus flag that I need to set manually so Update can see it has changed?
 
When you make a change in a datarow, a proposed version of the datarow is created. The proposed state becomes the current state when an endedit is called. Try Me.BindingContext(ds).EndCurrentEdit() (where ds is your data source object name) after the textbox value is changed and before the update call.


Jon
 
Last edited by a moderator:
Me.BindingContext(dsPlayer1).EndCurrentEdit();

//gives the error:

C:\Documents and Settings\Thomas\Mina dokument\Visual Studio Projects\TableHockey\Form3.cs(1306): The type or namespace name Me could not be found (are you missing a using directive or an assembly reference?)

I am new to .NET and I dont know how I should declare Me
 
this.BindingContext(dsPlayer1).EndCurrentEdit();

// sorry but still problems...
C:\Documents and Settings\Thomas\Mina dokument\Visual Studio Projects\TableHockey\Form3.cs(1306): System.Windows.Forms.Control.BindingContext denotes a property where a method was expected
 
Sorry but it does still not save the data.

If there is an endCurrentEdit do I need to do something like beginEdit too?

What does the DataGrid has that makes this happens automatically? There must be something extra that I should do for a textBox. But I cant find it in the documentation.


I tried this (connected a listbox as well to the dataset), not so nice, workaround and with this the data is saved. Is it that the current row in the dataset needs to lose "focus" to be able to be saved?

int index = listBox1.SelectedIndex;
listBox1.SelectedIndex=0;
listBox1.SelectedIndex=index;
oleDbDataAdapterPlayer.Update(dsPlayer1);
 
the rowstate is changed only when u move off the current row. so if u change
the value in the textbox, move to the next row, and then examine the
rowstate property, u will find that it has indeed changed to "Modified"

To cause the rowstate to change without moving off the row, call the
EndCurrentEdit method on the underlying bindingcontext object that u create,
or if uve not specifically created a bindingcontext, use the following
syntax (possibly in the click event of the OK/Save button)

Me.BindingContext(myDataTable).EndCurrentEdit
 
Last edited by a moderator:
NO IT IS DataTable

if you have DataSet then :

C#:
this.BindingContext[myDataSet,"TableName"].EndCurrentEdit()

or try (if you have DataTAble) -->
C#:
this.BindingContext[myDataTable,"ColumnName"].EndCurrentEdit()

:D
 
Back
Top