Solved

Update does not update database but does update Dataset

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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