Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.38 KB | None | 0 0
  1. Private Sub addBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addBtn.Click
  2.  
  3.         Try
  4.             'Trying to add a record to the weight lifting table based on the information the user provided in the text boxes
  5.             Dim insertCommand As New SqlDataAdapter("INSERT INTO WeightLifting VALUES(" & Integer.Parse(TextBox1.Text) & "," + "'" & Date.Parse(MaskedTextBox1.Text) & "'" + "," & Integer.Parse(TextBox3.Text) & "," + "'" + TextBox4.Text + "'" + ")", workoutsConnection)
  6.             insertCommand.Fill(WorkoutsDataSet.WeightLifting)
  7.             WorkoutsDataSet.WeightLifting.AcceptChanges()
  8.  
  9.             MessageBox.Show("Record added Successfully")
  10.  
  11.         Catch ex As Exception
  12.  
  13.             MessageBox.Show("You must provide data in all text boxes. The first text box must contain an integer. The second text box must contain a date. The third text box must contain an integer. The fourth text box must contain 'Weights'.")
  14.  
  15.         End Try
  16.  
  17.         'Refreshing the datagridview to show the updated data
  18.         DataGridView1.DataSource = WorkoutsDataSet.WeightLifting
  19.         WeightLiftingTableAdapter.Fill(WorkoutsDataSet.WeightLifting)
  20.  
  21.         'Clearing the text boxes after the add button was clicked for improved usability
  22.         TextBox1.Clear()
  23.         MaskedTextBox1.Clear()
  24.         TextBox3.Clear()
  25.         TextBox4.Clear()
  26.  
  27.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement