Criando a Classe Cliente Parte 2 em VB.net
Neste episódio vamos dar continuidade na criação da classe cadastro criando duas novas funções:
- DeleteCliente – remove um cliente do banco de dados.
- ConsultaDataSet – realiza consulta na tabela cliente e retorna os dados em um DataSet.
Veja o vídeo passo a passo abaixo:
Código completo da classe:
Imports System.Data.SqlClient Public Class CAD_CLIENTE #Region "Propriedades" Public Property ID As Integer Public Property NOME As String Public Property ENDERECO As String Public Property NUMERO As String Public Property TELEFONE As String #End Region #Region "Funçoes" Public Function NovoCliente(ByVal SQL As String, ByVal parametros As List(Of SqlParameter)) As Boolean Dim retorno As Boolean = True Dim banco As New DataAccess Try retorno = banco.ExecuteQuery(SQL, parametros) Catch ex As Exception Throw New Exception(ex.Message) Finally banco.CloseConn() End Try Return retorno End Function Public Function AtualizaCliente(ByVal SQL As String, ByVal parametros As List(Of SqlParameter)) As Boolean Dim retorno As Boolean = True Dim banco As New DataAccess Try retorno = banco.ExecuteQuery(SQL, parametros) Catch ex As Exception Throw New Exception(ex.Message) Finally banco.CloseConn() End Try Return retorno End Function Public Function DeleteCliente(ByVal SQL As String, ByVal parametros As List(Of SqlParameter)) As Boolean Dim retorno As Boolean = True Dim banco As New DataAccess Try retorno = banco.ExecuteQuery(SQL, parametros) Catch ex As Exception Throw New Exception(ex.Message) Finally banco.CloseConn() End Try Return retorno End Function Public Function ConsultaDataSet(ByVal SQL As String, ByVal parametros As List(Of SqlParameter)) As DataSet Dim ds As DataSet Dim banco As New DataAccess Try ds = banco.ExecuteDataSet(SQL, parametros) Catch ex As Exception Throw New Exception(ex.Message) Finally banco.CloseConn() End Try Return ds End Function #End Region End Class