Using a messagebox to give the user a choice(Yes/No). When I choose - No - it still removes the info from the datagrid and lowers the number on the navigator by 1. How can I alter this code to not remove the data in the datagrid and not change the count in the navigator when No is selected?
Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HomeInventory.mdf;Integrated Security=True; Connect Timeout=30;User Instance=True;")
Dim myAdapter As SqlDataAdapter = New SqlDataAdapter("DeleteItem", myConnection)
If MessageBox.Show("Are you sure you want to delete this record? ", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
Exit Sub
ElseIf (Windows.Forms.DialogResult.Yes) Then
Dim ds As DataSet = New DataSet
myAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
myAdapter.SelectCommand.Parameters.Add(
New SqlParameter("@ItemID", SqlDbType.Int))
myAdapter.SelectCommand.Parameters(
"@ItemID").Value = ItemIDTextBox.Text
myAdapter.SelectCommand.Connection.Open()
myAdapter.Fill(ds,
"ItemDescription")
End If
Thanks
John
Enter your message below
Sign in or Join us (it's free).