Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Update does not update database but does update Dataset

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 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