Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 149,130 times

Contents

Downloads

Related Categories

An Introduction to VB.NET and Database Programming - Finishing Up

SilverLock

Finishing Up

Adding data is done by first clearing the fields and then using the BindingManager to add a new row. Then the user must fill out the text fields and click the update button. The code for the Add button and Update button is below:

Private Sub btnAdd_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
     txtTitle.Text = ""
     DsRecipes1.Recipes.Clear()
     RecipesBindingManager.AddNew()
     bNewRow = True Me .SetEntryControls( True )
     Me.SetMaintenanceButtons( False )
     Me.SetComboBoxControls( False )
     cboCategory.Enabled = True
     txtCategory.Visible = True
     lblCategoryText.Visible = True
     txtTitle.Focus()
End Sub

Private Sub btnUpdate_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

If ValidData() Then
     RecipesBindingManager.EndCurrentEdit()
     Me.UpdateDatabase()
     If bNewRow Then
          cboRecipe.SelectedIndex = RecipesBindingManager.Count - 1
          bNewRow = False
     End If
     Me.SetEntryControls( False )
     Me.SetComboBoxControls( True )
     btnUpdate.Enabled = False
     Me.SetMaintenanceButtons( True )
     EditMode = False
     cboCategory.Focus()
End If

txtCategory.Visible = False
lblCategoryText.Visible = False

End Sub

That covers the basics of how to use your data connections, data adapters, and data sets to retrieve, navigate, add, delete and update data. I hope that these simple instructions have helped you gain a better understanding of how to manipulate a DataSet. Please feel free to write me or post your comments here about your experiences. There will be more of these beginner type articles as well as book reviews from a beginner's perspective to help guide those of us that are new to the world of Visual Basic.

Comments