Este es mi código
De mi Form 1
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conectarse()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim id As String
id = TextBox1.Text
consultar(id)
End Sub
End Class
De mi modulo
New OleDb.OleDbCommand
Public dr As OleDb.OleDbDataReader
Public Sub conectarse()
Try
conn.Open()
MsgBox("Conexion Exitosa")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub consultar(ByRef identificacion As String)
cmd.Connection = conn
cmd.CommandType = CommandType.Text
If identificacion <> "" Then
cmd.CommandText = "SELECT NOMBRES, APELLIDOS, CORREO, DIRECCION FROM PERSONA WHERE IDPERSONA=" + identificacion
Else
cmd.CommandText = "SELECT NOMBRES, APELLIDOS, CORREO, DIRECCION FROM PERSONA "
End If
Try
dr = cmd.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 existen registros para la consulta")
End If
dr.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Module