[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

Dataset Updates not saving to database

Hello,

I have a problem with a windows form.  I am loading data from an Access database into a dataset and then using a dataview.rowfilter to find and display the desired row.  The problem comes in when I try to save the changes made by the user back to the database.  The code works find and no errors are received but the changes are not saved in the database.  Please tell me what I am doing wrong!!  Here is the code I am using to save the changes:

 On Error GoTo saveerror

        OleDbConnection1.Open()
        Me.BindingContext(Me.CompEdit1, "Complaints").EndCurrentEdit()
        Me.OleDbDataAdapter1.Update(Me.CompEdit1, "Complaints")
        Me.CompEdit1.AcceptChanges()
        OleDbConnection1.Close()

        Dim a As New frmAdminSub
        Me.Close()
        a.Show()
saveerror:
        'MessageBox.Show(Err.Description)
        Err.Clear()
    End Sub
0
im4osu
Asked:
im4osu
1 Solution
 
chaniewskimCommented:
Try to invoke EndEdit() method on current row ow dataset table, and not on bindingContext. I also had some problems with that, and this way it worked like a charm.

0
 
ramesh12Commented:
Use OLEDBCommandBuilder to build your Update command like this

dim odb as oledbcommandbuilder

odb=new OLEDBCommandBuilder(Me.OleDbDataAdapter1)

Me.OleDbDataAdapter1.updateCommand=odb.Getupdatecommand()

Me.OleDbDataAdapter1.update(Me.CompEdit1, "Complaints")

Syntactically there may be some errors. Use something like the above and it shold work
0
 
nishikanthCommented:
change the position of the contextr....



Me.BindingContext(ds.Tables(0)).Position += 1 'force to a new row so the current row is marked 'modified'

That forces the datagrid table pointer to go to the next record, and thus mark the row as 'modified'.
0
 
im4osuAuthor Commented:
Thanks nishikanth,

Your solution worked like a charm!!  It was great only having to add one line to my existing code to get it to work.  My new code looks like this:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        On Error GoTo saveerror

        Me.BindingContext(CompEdit1.Tables(0)).Position += 1

        OleDbConnection1.Open()
        Me.BindingContext(Me.CompEdit1, "Complaints").EndCurrentEdit()
        Me.OleDbDataAdapter1.Update(Me.CompEdit1, "Complaints")
        Me.CompEdit1.AcceptChanges()
        OleDbConnection1.Close()

        Dim a As New frmAdminSub
        Me.Close()
        a.Show()
saveerror:
        'MessageBox.Show(Err.Description)
        Err.Clear()
    End Sub
0
 
nishikanthCommented:
glad it worked...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now