thomas10001 Posted June 22, 2003 Posted June 22, 2003 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? Quote
Moderators Robby Posted June 23, 2003 Moderators Posted June 23, 2003 Can you post your relevant code? Quote Visit...Bassic Software
thomas10001 Posted June 23, 2003 Author Posted June 23, 2003 // code for loading, which works fine dsPlayer1.Clear(); oleDbDataAdapterPlayer.Fill(dsPlayer1); // code for saving, which doesnt work oleDbDataAdapterPlayer.Update(dsPlayer1); Quote
thomas10001 Posted June 23, 2003 Author Posted June 23, 2003 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? Quote
Moderators Robby Posted June 23, 2003 Moderators Posted June 23, 2003 Is the textbox bound to the Dataset? Quote Visit...Bassic Software
thomas10001 Posted June 23, 2003 Author Posted June 23, 2003 Yes the textbox is bound to the dataset via the text property. Quote
*Experts* jfackler Posted June 23, 2003 *Experts* Posted June 23, 2003 (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 June 23, 2003 by jfackler Quote
thomas10001 Posted June 24, 2003 Author Posted June 24, 2003 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' Quote
Administrators PlausiblyDamp Posted June 24, 2003 Administrators Posted June 24, 2003 if you are using C# the VB Keyword Me is replaced with the keyword this. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
thomas10001 Posted June 24, 2003 Author Posted June 24, 2003 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 Quote
Moderators Robby Posted June 24, 2003 Moderators Posted June 24, 2003 try this... this.BindingContext[dsPlayer1].EndCurrentEdit(); Quote Visit...Bassic Software
thomas10001 Posted June 24, 2003 Author Posted June 24, 2003 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); Quote
sizer Posted June 24, 2003 Posted June 24, 2003 (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 June 24, 2003 by sizer Quote Some people are wise and some are other-wise.
thomas10001 Posted June 24, 2003 Author Posted June 24, 2003 is myDataTable the DataSet? I have tried this.BindingContext[dsPlayer1].EndCurrentEdit(); with no success in saving Quote
sizer Posted June 24, 2003 Posted June 24, 2003 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 Quote Some people are wise and some are other-wise.
sizer Posted June 24, 2003 Posted June 24, 2003 hm??? do you use .AcceptChanges() before update? if you use ,,well DONT :D :D (use it after update) Quote Some people are wise and some are other-wise.
thomas10001 Posted June 24, 2003 Author Posted June 24, 2003 Thank you!!! This made it to work! this.BindingContext[myDataSet,"TableName"].EndCurrentEdit() (No I don't use .AcceptChanges() at all) Quote
sizer Posted June 24, 2003 Posted June 24, 2003 :D :::BTW:::D my advice is Use .AcceptChanges() after every Update() Quote Some people are wise and some are other-wise.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.