An Introduction to VB.NET and Database Programming

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.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.”