Solved

Dataset Updates not saving to database

Posted on 2004-04-19
5
448 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
glad it worked...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

11 Experts available now in Live!

Get 1:1 Help Now