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
Solved

Dataset Updates not saving to database

Posted on 2004-04-19
5
478 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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