Databinding to a textbox

Hi,

I want something that I expect to be very simple, but for some reason things are not working as I expect.

I have a Textbox which I want to bind to a field in a database.

I also want to use the BindingNavigator.

I have the following Form_Load

private void JournalView_Load(object sender, EventArgs e)
{
this.journalEntryTableAdapter.Fill(this.goalsplannerDataSet.JournalEntry);
if (this.goalsplannerDataSet.JournalEntry.Count == 0)
{
DataRow r = this.goalsplannerDataSet.JournalEntry.NewRow();
r["date"] = (DateTime)this.dateTimePicker.Value;
r["Memo"] = (string)textBoxMemo.Text; // initialy empty
r["Title"] = (string)textBoxMemoTitle.Text; // initially empty
this.goalsplannerDataSet.JournalEntry.Rows.Add(r);
}
}

The idea is to always have a new database entry when there are no entries yet.

private void JournalView_FormClosed(object sender, FormClosedEventArgs e)
{
journalEntryTableAdapter.Update(this.goalsplannerDataSet.JournalEntry);
}

This should store all results in the database. When I debug and look into the dataset that I use to update, it contains all the data as expected. However, when I return to my view again (consequently the load is called again), then the text Memo and Title fields are empty in the dataset.

When I press the + button on the BindingNavigator first, all field properly enter the database. What happens

This is always the case. When I press the + button, this last entries never enters the dataset. I expected that the binding would take case of this, but it does not seem to work as I expected.

I also tried using an additional event handler when text is changed in the textboxes to update the Memo and Title field. Then they do enter the dataset, but when calling journalEntryTableAdapter.Update(this.goalsplannerDataSet.JournalEntry); they still do not make it to the database.

I am not getting any exceptions or warning, so everything appears to go well. Same here... when loading the form again, the Memo and Text field are empty in the dataset.

What am I doing wrong

Regards,

Ruud Wijnands



Answer this question

Databinding to a textbox

  • Morn

    Maybe this will help.


  • Dwight Kulkarni

    Nope. I am familiar with this issue. That is not the problem. I also have this problem while debugging the applicatin. Studio only overwrites when I run the application again.
  • Databinding to a textbox