Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub addBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addBtn.Click
- Try
- 'Trying to add a record to the weight lifting table based on the information the user provided in the text boxes
- Dim insertCommand As New SqlDataAdapter("INSERT INTO WeightLifting VALUES(" & Integer.Parse(TextBox1.Text) & "," + "'" & Date.Parse(MaskedTextBox1.Text) & "'" + "," & Integer.Parse(TextBox3.Text) & "," + "'" + TextBox4.Text + "'" + ")", workoutsConnection)
- insertCommand.Fill(WorkoutsDataSet.WeightLifting)
- WorkoutsDataSet.WeightLifting.AcceptChanges()
- MessageBox.Show("Record added Successfully")
- Catch ex As Exception
- 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'.")
- End Try
- 'Refreshing the datagridview to show the updated data
- DataGridView1.DataSource = WorkoutsDataSet.WeightLifting
- WeightLiftingTableAdapter.Fill(WorkoutsDataSet.WeightLifting)
- 'Clearing the text boxes after the add button was clicked for improved usability
- TextBox1.Clear()
- MaskedTextBox1.Clear()
- TextBox3.Clear()
- TextBox4.Clear()
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement