Question Problem Updating Database From A Bound Control

Joined
Sep 1, 2009
Messages
6
Programming Experience
5-10
Hi all,

i have a form with 2 visible controls (a textbox and a combo box).

when the form loads i create a data adapter as follows

VB.NET:
daSurveyDetail = New SqlCeDataAdapter(strSQL_Global, myConnection)
daSurveyDetail.Fill(dsSurveyDetail, "dsSurveyDetail")
cbSurveyDetail = New SqlCeCommandBuilder(daSurveyDetail)  
daSurveyDetail.UpdateCommand = cbSurveyDetail.GetUpdateCommand

and then bind the textbox

VB.NET:
Me.txtAgeYear.DataBindings.Add(New Binding("Text", dsSurveyDetail, "dsSurveyDetail.existingAgeBand"))

i also have 2 buttons to navigate through the dataset

VB.NET:
Private Sub butMoveNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butMoveNext.Click
        Me.BindingContext(dsSurveyDetail).EndCurrentEdit()
        daSurveyDetail.Update(dsSurveyDetail.Tables(0))
        Me.BindingContext(dsSurveyDetail, "dsSurveyDetail").Position = Me.BindingContext(dsSurveyDetail, "dsSurveyDetail").Position + 1
End Sub

Private Sub butMovePrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butMovePrevious.Click
        Me.BindingContext(dsSurveyDetail).EndCurrentEdit()
        daSurveyDetail.Update(dsSurveyDetail.Tables(0))
        Me.BindingContext(dsSurveyDetail, "dsSurveyDetail").Position = Me.BindingContext(dsSurveyDetail, "dsSurveyDetail").Position - 1
End Sub

if i manually go into the text box and change the value, then move next and move previous i can see that the value that i entered is saved within the dataset.

however what i actually want to do is populate the text box with the selectedValue of the combobox. so what i have done is added the following code to the combobox's selectedIndexChanged event

VB.NET:
Me.txtAgeYear.Text = Me.cboAge1to20.SelectedValue

when i change the combobox i can see that the value in the text box has changed, but if i move next and move previous the text box does not hold the value selected by the combo box.

can anyone shed any light into where i am going wrong.
 
Back
Top