Solved

Update does not update database but does update Dataset

Posted on 2011-02-21
3
519 Views
Last Modified: 2013-11-26
I have a simple SQL database that I've created in visual basic 2008 express edition. I created a new form and created a datasource using the datasource configuration wizard. I then dragged  the datasource to the  new form that I created  and this created a gridview that I'm able to add, update and delete.

During runtime everything works perfectly but if I look in the acutal database table, nothing has changed at all, it almost seems like it's just the datatable  that's changing but the changes in the datatable are not being updated to the physical table in the sql database. Am I correct in thinking that the table adapter is meant to take care of this.

The the only other thing I've done that might affect it is the form is brought up by selecting a button, when this button is selected. I create a new instance of the above form  i.e.

 Dim newIncident As New Incident
 newIncident.Show()

This is the code that is automatically generated:



Private Sub IncidentRecordBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IncidentRecordBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.IncidentRecordBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.KEDBDataSet1)

    End Sub

    Private Sub Incident_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'KEDBDataSet1.IncidentRecord' table. You can move, or remove it, as needed.
        Me.IncidentRecordTableAdapter.Fill(Me.KEDBDataSet1.IncidentRecord)

    End Sub

Open in new window

0
Comment
Question by:Michael Roodt
3 Comments
 
LVL 14

Expert Comment

by:Daniel Junges
ID: 34945269
try the follow to save the data into database

if(Me.KEDBDataSet1.HasChange())
  Me.IncidentRecordTableAdapter.Update(Me.KEDBDataSet1.GetChanges() );
0
 
LVL 1

Expert Comment

by:imonfireDAMMIT
ID: 34950696
I believe you have to commit the changes that were made with .Commit
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 34951789
hi ...Try this one....
Private Function Save() As Boolean
        
        Dim Saved As Boolean = False
        If Me.KEDBDataSet1.HasChanges Then
            Try
                Dim IncidentRecordUpdates() As DataRow = Me.KEDBDataSet1.IncidentRecord.Select("", "", DataViewRowState.Added Or DataViewRowState.ModifiedCurrent)
                Me.IncidentRecordTableAdapter.Update(IncidentRecordUpdates)

                Dim IncidentRecordDeletes() As DataRow = KEDBDataSet1.IncidentRecord.Select("", "", DataViewRowState.Deleted)
                Me.IncidentRecordTableAdapter.Update(IncidentRecordDeletes)
                Saved = True

            Catch ex As SqlException
             End Try
        End If
        Return Saved
     End Function


Private Sub IncidentRecordBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IncidentRecordBindingNavigatorSaveItem.Click
 Me.Validate()
         Me.IncidentRecordBindingSource.EndEdit()
        If Me.Save Then
            MessageBox.Show("Data Saved", "Changes Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

    End Sub

Open in new window

Hope it helps jtoutou
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

14 Experts available now in Live!

Get 1:1 Help Now