Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dataset Updates not saving to database

Posted on 2004-04-19
5
Medium Priority
?
497 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

618 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