Imports System.Data
Imports System.Data.SqlClient
Public Function LeBanco(ByVal strConexao As String, ByVal sSql As String) As DataSet
Dim dataAdapter As SqlDataAdapter
Dim DataSet As New DataSet
Dim Conexao As SqlConnection
Try
Conexao = New SqlConnection(strConexao)
Conexao.Open()
dataAdapter = New SqlDataAdapter(sSql, Conexao)
dataAdapter.Fill(DataSet, "Dados")
Conexao.Close()
Return DataSet
Catch ex As Exception
Return Nothing
End Try
End Function
Public Function ExecutaBanco(ByVal strConexao As String, ByVal sSql As String, Optional ByVal InserirTransacao As Boolean = True) As Boolean
Dim sAux As String
Dim Conexao As SqlConnection = New SqlConnection(strConexao)
Try
'Define a transação
If InserirTransacao = True Then
sAux = "BEGIN TRAN " & sSql & " COMMIT TRAN"
Else
sAux = sSql
End If
Dim Comando As SqlCommand = New SqlCommand(sAux, Conexao)
Conexao.Open()
Comando.ExecuteNonQuery()
Conexao.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
Nenhum comentário:
Postar um comentário