Field not being saved to DB even when bound textbox shows changed data

  • Thread starter Thread starter Johann Blake
  • Start date Start date
J

Johann Blake

I have a form with a single textbox control which is bound to a
DataRelation in a typed dataset. The textbox displays the name of the
product depending on the language selected from a combobox. When you
select a different language, the textbox must show the name of the
product in the selected language. This is done by setting the RowFilter
property of the DefaultView on the table where the text comes from. If
no text exists (that is, no record exists) for the selected language, a
new record is added to the table for that language (I do this manually
in code). I managed to get this to work. I can even change back and
forth between two languages where there is text and see that the
databindings are working. I can even change the text in one language,
switch to another language and then back and I do see that the changed
text is still there. The problem comes when I try to save the changed
text. If I run my app and want to enter text for, say English, and then
I enter text for German, and then execute the Update method on the data
adapter, two records are stored in the table in the database but the
text for German is empty. But I can see the text for both languages
when I switch languages on the form with the combobox. The text for
both languages by the way are stored in the same column. A separate
column, called LanguageID is used to identify the actual language. When
I initially add a new record for a language that doesn't currently have
text for that language, I set the text to an empty string. It appears
that it is this empty string that is getting stored and not the current
value I enter in the textbox. Any idea why the text for the new record
is not saved? The text will always be saved for the first new record I
add but never for the second record. It almost appears that the problem
has to do with the CurrencyManager not moving to the next row which
would cause saving of the current row. I do perform a EndCurrentEdit
but this does not help.

This problem has plagued me all day yesterday.

Thanks for your help
Johann Blake
 
When I execute the EndCurrentEdit using the BindingContext of the
textbox, the data will get saved. If I execute the EndCurrentEdit using
the BindingContext of the DataRelation used to store the text, it does
not get saved. In code...

// This line causes the current value to be stored in the database.
this.txtProductName.BindingContext[this.datasetFoodLabels.TextLanguages].EndCurrentEdit();


// This line results in the current value NOT being saved.
this.BindingContext[this.datasetFoodLabels,
"Text.Relation_Text_TextLanguages_TextID.Text"].EndCurrentEdit();

I even tried this, which does not work:
this.BindingContext[this.datasetFoodLabels,
"TextLanguages"].EndCurrentEdit();

So the question is, why does saving occur when the BindingContext is
applied to the textbox but doesn't when using just 'this'?

Johann
 
Back
Top