0% found this document useful (0 votes)
23 views1 page

Class1: "Provider Microsoft - ACE.OLEDB.12.0 " "Data Source Database21.accdb "

This class defines methods for executing queries on an Access database. It opens a connection to the database, prepares command objects with any parameters, executes the command to fill a data table, and closes the connection. Key aspects include opening and closing the database connection, adding any parameters to the command, executing the command to populate a data table, and handling exceptions.

Uploaded by

Keylan SC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

Class1: "Provider Microsoft - ACE.OLEDB.12.0 " "Data Source Database21.accdb "

This class defines methods for executing queries on an Access database. It opens a connection to the database, prepares command objects with any parameters, executes the command to fill a data table, and closes the connection. Key aspects include opening and closing the database connection, adding any parameters to the command, executing the command to populate a data table, and handling exceptions.

Uploaded by

Keylan SC
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Imports System.Data.

OleDb

Public Class Class1

'crear la coneccion
Private DBCon As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" &
"Data Source=Database21.accdb;")
'preparar DB Command
Private DBCmd As OleDbCommand

'DB data
Public DBDA As OleDbDataAdapter
Public DBDT As DataTable

'Parametros del Query


Public Params As New List(Of OleDbParameter)

'Estadisticos del Query


Public RecordCount As Integer
Public Exception As String

Public Sub ExecQuery(Query As String)


' Reset Estadisticos del Query
RecordCount = 0
Exception = ""

Try
'Abrir la coneccion
DBCon.Open()

'Crear DB command
DBCmd = New OleDbCommand(Query, DBCon)

'Cargar Parametro en DB command


Params.ForEach(Sub(p) DBCmd.Parameters.Add(p))

'Limpiar los parametros de la lista


Params.Clear()

'Ejecutar Command y llenar la Datatable


DBDT = New DataTable
DBDA = New OleDbDataAdapter(DBCmd)
RecordCount = DBDA.Fill(DBDT)

Catch ex As Exception
Exception = ex.Message
End Try
'Cerrar Conección
If DBCon.State = ConnectionState.Open Then DBCon.Close()

End Sub
'Incluir Parametros del Query & Command
Public Sub AddParam(Name As String, Value As Object)
Dim NewParam As New OleDbParameter(Name, Value)
Params.Add(NewParam)

End Sub

End Class

You might also like