O'Reilly logo

ADO.NET Programming in Visual Basic™ .NET by Bob Howell, Steve Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Updating the Database

To make this easier, we are going to create a method that we will call to update the database. We could probably emulate the old ADO Data Control’s behavior, but instead let’s create an UpdateChanges method:

Public Sub UpdateChanges() 
    Dim dsTemp As DataSet 

    Try 
       If mAdapter.InsertCommand.CommandText = "" And _ 
           mAdapter.UpdateCommand.CommandText = "" And _ 
           mAdapter.DeleteCommand.CommandText = "" Then 
            Exit Sub 
       End If 
       Me.ParentForm.BindingContext(Me).EndCurrentEdit() 
       If mDataSet.HasChanges Then 

mAdapter.Update(mDataSet.Tables(mintBoundTable).GetChanges) 
          mDataSet.AcceptChanges() 
          mDataSet.Clear() 
          mAdapter.Fill(mDataSet, mintBoundTable) 
       End If 
    Catch errobj As Exception 
        Throw errobj 
    End Try 
End Sub 

First the procedure tests if ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required