Solved

Dataset Updates not saving to database

Posted on 2004-04-19
5
456 Views
Last Modified: 2009-07-29
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
Comment
Question by:im4osu
5 Comments
 
LVL 5

Expert Comment

by:chaniewskim
ID: 10863576
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
 
LVL 7

Expert Comment

by:ramesh12
ID: 10865033
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
 
LVL 8

Accepted Solution

by:
nishikanth earned 500 total points
ID: 10865488
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
 

Author Comment

by:im4osu
ID: 10869997
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
 
LVL 8

Expert Comment

by:nishikanth
ID: 10874689
glad it worked...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short film showing how OnPage and Connectwise integration works.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now