Been on this one all day to day and just cant seem to get it working !!! Hence this cry for help..
Have a form with one combobox and one text box bound to a dataset:
__________________________________________________
Try
dsCountry = objCountry.All call to middle-tier
Catch exc As Exception
MsgBox(exc.Message, , "error")
End Try
cboCountryCode.DataSource = dsCountry.Tables("Country")
cboCountryCode.DisplayMember = "CountryCode"
txtDescription.DataBindings.Add("Text", dsCountry.Tables ("Country"), "Description")
___________________________________________________
I want to be able to click a button called New:
___________________________________________________
Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
blnNewTag = True
Me.BindingContext(dsCountry.Tables("Country")).EndCurrentEdit()
___________________________________________________
To indicate that I wish to add a new record. And then type in the new information into the combobox and the textbox and save it, using the Save button:
___________________________________________________
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Dim NewRow As DataRow = dsCountry.Tables("Country").NewRow() retrieves a copy of the row structure
NewRow.Item("CountryCode") = cboCountryCode.Text
NewRow.Item("Description") = txtDescription.Text
dsCountry.Tables("Country").Rows.Add(NewRow)
BindingContext(dsCountry.Tables("Country")).EndCurrentEdit()
Dim dsChanges As DataSet = dsCountry.GetChanges()
Try
If Not dsChanges Is Nothing Then
blnRetVal = objCountry.Update(dsChanges) writes changes to the database via the n-tier architecture
dsCountry.AcceptChanges() commits the changes
End If
Catch exc As Exception
dsCountry.RejectChanges()
MsgBox(exc.Message, , "error")
End Try
If blnRetVal = True Then MsgBox("Record Successfully Saved", , "error")
Me.BindingContext(dsCountry.Tables("Country")).Position = 0
___________________________________________________
The error I am getting is that a blank record is being added in place of the combobox text, but the textbox text is being added OK. I think its a problem with databinding, but just cant seem to work it out...
Any help would be gladly welcomed as I have a headache after looking at this stuff.
Thanks
Have a form with one combobox and one text box bound to a dataset:
__________________________________________________
Try
dsCountry = objCountry.All call to middle-tier
Catch exc As Exception
MsgBox(exc.Message, , "error")
End Try
cboCountryCode.DataSource = dsCountry.Tables("Country")
cboCountryCode.DisplayMember = "CountryCode"
txtDescription.DataBindings.Add("Text", dsCountry.Tables ("Country"), "Description")
___________________________________________________
I want to be able to click a button called New:
___________________________________________________
Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
blnNewTag = True
Me.BindingContext(dsCountry.Tables("Country")).EndCurrentEdit()
___________________________________________________
To indicate that I wish to add a new record. And then type in the new information into the combobox and the textbox and save it, using the Save button:
___________________________________________________
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Dim NewRow As DataRow = dsCountry.Tables("Country").NewRow() retrieves a copy of the row structure
NewRow.Item("CountryCode") = cboCountryCode.Text
NewRow.Item("Description") = txtDescription.Text
dsCountry.Tables("Country").Rows.Add(NewRow)
BindingContext(dsCountry.Tables("Country")).EndCurrentEdit()
Dim dsChanges As DataSet = dsCountry.GetChanges()
Try
If Not dsChanges Is Nothing Then
blnRetVal = objCountry.Update(dsChanges) writes changes to the database via the n-tier architecture
dsCountry.AcceptChanges() commits the changes
End If
Catch exc As Exception
dsCountry.RejectChanges()
MsgBox(exc.Message, , "error")
End Try
If blnRetVal = True Then MsgBox("Record Successfully Saved", , "error")
Me.BindingContext(dsCountry.Tables("Country")).Position = 0
___________________________________________________
The error I am getting is that a blank record is being added in place of the combobox text, but the textbox text is being added OK. I think its a problem with databinding, but just cant seem to work it out...
Any help would be gladly welcomed as I have a headache after looking at this stuff.
Thanks