0% found this document useful (0 votes)
19 views

"DSN Prueba Uid " " PWD " " ": Conexion Odbcdatareader Odbcconnection Odbccommand

This document defines two classes - Conexion and Prueba - that manage database connections and queries. The Conexion class handles database connections, commands, and readers. It includes methods to open/close connections, execute queries, and return data readers. The Prueba class instantiates a Conexion object and includes an event handler for a button click. The handler uses the Conexion object to check if an account exists by name before inserting new data.

Uploaded by

Leslie Perez
Copyright
© Attribution Non-Commercial (BY-NC)
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)
19 views

"DSN Prueba Uid " " PWD " " ": Conexion Odbcdatareader Odbcconnection Odbccommand

This document defines two classes - Conexion and Prueba - that manage database connections and queries. The Conexion class handles database connections, commands, and readers. It includes methods to open/close connections, execute queries, and return data readers. The Prueba class instantiates a Conexion object and includes an event handler for a button click. The handler uses the Conexion object to check if an account exists by name before inserting new data.

Uploaded by

Leslie Perez
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 2

Public Class Conexion Public Reader As Odbc.OdbcDataReader Public conectar As Odbc.OdbcConnection Public comando As Odbc.

OdbcCommand Dim usuario, password As String Public Sub conexion(ByVal usuario As String, ByVal password As String) Try If conectar.State = ConnectionState.Closed Then conectar.ConnectionString = "DSN=prueba;Uid=" & usuario & ";pwd=" & password & ";" conectar.Open() End If Catch ex As Exception MsgBox("No se puede establecer la conexion a la base de datos") End Try End Sub Public Sub New(ByVal usuario As String, ByVal password As String) End Sub Public Sub New() conexion(usuario, password) End Sub Public Sub ddl(ByVal peticion As String) Try If Not conectar.State = ConnectionState.Open Then conectar.Open() End If Dim Comando As New Odbc.OdbcCommand(peticion, conectar) Comando.ExecuteNonQuery() conectar.Close() MsgBox("Proceso realizado con exito.") Catch ex As Exception conectar.Close() MsgBox(ex.Message, vbCritical, "Error") End Try End Sub Function Consulta(ByVal Peticion As String) As Odbc.OdbcDataReader Try If Not conectar.State = ConnectionState.Open Then conectar.Open() End If Dim Comando As New Odbc.OdbcCommand(Peticion, conectar) Comando.ExecuteNonQuery() Reader = Comando.ExecuteReader Return Reader Catch ex As Exception conectar.Close() MsgBox(ex.Message, MsgBoxStyle.Critical, "Error") Return Nothing End Try End Function End Class

Public Class Prueba Public Conec As New Conexion("root", "root") Public peticion As String Public buscar As Odbc.OdbcDataReader Private Sub Prueba_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click peticion = "select * from CatalogoCuentas where DescripcionCuenta=" & Me.TextBox2.Text buscar = Conec.Consulta(peticion) While buscar.Read MsgBox("Ya existe la Cuenta con ese Nombre") Exit Sub End While peticion = "insert into CatalogoCuentas values('" & Me.TextBox1.Text & "','" & Me.TextBox1.Text & "','" & Me.TextBox1.Text & "')" Conec.ddl(peticion) End Sub End Class

You might also like