Link to home
Start Free TrialLog in
Avatar of rodneygray
rodneygrayFlag for United States of America

asked on

Visual Studio Visual Basic 2012, Automatically update a record when moving to next record without need for save button

Trying to see if I can teach an old dog(me) new tricks. After years of using Access to create databases, I am trying to use Visual Studio 2012 Visual Basic to re-create some of the applications I have created. Right now my learning curve is more of a straight line than a curve. I am used to Microsoft Access handling all record update functions for me. I used the before update event for data validation. Then, if no errors were found, Access would write the updated data to the table. Not so with VB 2012. How do I get VB 2012 to error check a record before the update is written and then, if no errors are found, to write the changes (and/or add a new record) when moving to a new record. I have purchased a couple of books on VB 2012 and I cannot find the answer in any of them. I can't find it online. As a side issue, is there a book/tutorial that anyone could recommend that deals pretty much exclusively with handling databases? I would like to find one that takes me, step by step, thru the creation of a small vb project that updates data located in a SQL server.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rodneygray

ASKER

Found the solution on http://www.codeproject.com/Articles/12846/Auto-Saving-DataGridView-Rows-to-a-SQL-Server-Data
Had to add two subroutines and one class variable. Might need to add me.Validate(), have not tested yet.


Public Class SizeForm
    Dim UpdatePending As Boolean = False

   
Private Sub SizeBindingSource_ListChanged(sender As Object, e As System.ComponentModel.ListChangedEventArgs) Handles SizeBindingSource.ListChanged
        If Me.SupplyRoomDataSet.HasChanges Then
            Me.UpdatePending = True
        End If
    End Sub


Private Sub SizeDataGridView_RowValidated(sender As Object, e As DataGridViewCellEventArgs) Handles SizeDataGridView.RowValidated
        If UpdatePending Then
            Me.SizeTableAdapter.Update(Me.SupplyRoomDataSet)
            Me.UpdatePending = False
        End If
    End Sub
End Class