Solved

Update does not update database but does update Dataset

Posted on 2011-02-21
3
522 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

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

18 Experts available now in Live!

Get 1:1 Help Now