Anda di halaman 1dari 5

Nombre: basededatos

Modulo: conectardb.vb

Nombre de la base de datos:codigo


Guardarla dentro de la carpeta de visual”debug”
Tabla: persona o usuarios
Campos:idPersona, nombres, apellidos, correo, direccion
Module funcionesdb
Public conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=codigo.accdb;Persist Security Info=False")

Public Sub conectarse()


Try
Conn.Open()
MsgBox("si se conecto")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


conectarse()

End Sub
parte2

Module funcionesdb
Public conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=codigo.accdb;Persist Security Info=False")
Public bdd As New OleDb.OleDbCommand
Public dr As OleDb.OleDbDataReader
Public Sub conectarse()

Public Sub consultar(ByRef identificacion As String)


bdd.Connection = conn
bdd.CommandType = CommandType.Text
If identificacion <> " " Then
bdd.CommandText = "SELECT NOMBRES, APELLIDOS, CORREO, DIRECCION FROM PERSONA WHERE IDPERSONA=" + identificacion
Else
bdd.CommandText = "SELECT NOMBRES, APELLIDOS, CORREO, DIRECCION FROM PERSONA WHERE IDPERSONA"
End If
Try
dr = bdd.ExecuteReader()

If dr.HasRows Then
While dr.Read()
MsgBox(dr(0).ToString + " " + dr(1).ToString + " " + dr(2).ToString + " " + dr(3).ToString)
End While
Else
MsgBox("no existe registro")

End If
dr.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Module
Codigo boton

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim id As String
id = TextBox1.Text
consultar(id)
End Sub
End Class

Anda mungkin juga menyukai