This is what you need i think
Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
If TxtPIS.Text = "" Then
MsgBox("Please Enter PIS No and Correct Batch NO")
TxtPIS.Focus()
Exit Sub
Else
Dim con As String, RecordsAffected As Integer
Try
Using Mycon As New SqlConnection(con)
Mycon.Open()
Using cmd As New SqlCommand("sptblTrg_detail_Delete", Mycon)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@Course_Id", TxtCourseID.Text)
RecordsAffected = cmd.ExecuteNonQuery()
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If RecordsAffected > 0 Then
MessageBox.Show("Detail Deleted Successfully")
clearall()
Dgvtrainees.DataSource = Nothing
Else
MessageBox.Show("Problem in Deleting")
End If
End Try
End If
End Sub