?
Solved

Update does not update database but does update Dataset

Posted on 2011-02-21
3
Medium Priority
?
532 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
[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
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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

743 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