Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 doesn't 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?

Posted

// code for loading, which works fine

dsPlayer1.Clear();

oleDbDataAdapterPlayer.Fill(dsPlayer1);

 

// code for saving, which doesnt work

oleDbDataAdapterPlayer.Update(dsPlayer1);

Posted

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?

  • *Experts*
Posted (edited)

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

Edited by jfackler
Posted

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'

Posted

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

Posted

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 can't 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);

Posted (edited)

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 u've not specifically created a bindingcontext, use the following

syntax (possibly in the click event of the OK/Save button)

 

Me.BindingContext(myDataTable).EndCurrentEdit

Edited by sizer
Some people are wise and some are other-wise.
Posted

NO IT IS DataTable

 

if you have DataSet then :

 

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

 

or try (if you have DataTAble) -->

this.BindingContext[myDataTable,"ColumnName"].EndCurrentEdit()

 

:D

Some people are wise and some are other-wise.
Posted

hm???

 

do you use .AcceptChanges() before update?

 

if you use ,,well DONT :D :D (use it after update)

Some people are wise and some are other-wise.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...