Você está na página 1de 6

UNIVERSIDAD LIBRE

FACULTAD DE INGENEIRIA
INGENIERIA INDUSTRIAL
ELECTIVA DE INFORMATICA I
TEMA: CONSULTAS
1. Ingre a visual y abra su proyecto y disee la siguiente forma:
TXTNUMERO

BRACEPTAR

TableLayoutPanel1 Lbiden Lbnom Lbdir


COPIE EL SIGUIENTE CODIGO:

TXTNOMBRE

Lbcargo

GPNOMBRE

BT2

VISIBLE FALSE

Imports System.IO
Imports System.Data.OleDb

Public Class consultaem


Dim oConn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\DATOS\NUTRISUS.accdb")
Dim CMD As New OleDbCommand
Dim DR As OleDbDataReader
Dim nivel As String
Public NOM As String

Private Sub Txtnumero_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Txtnumero.KeyPress


If e.KeyChar = Convert.ToChar(Keys.Return) Then
e.Handled = True
If UCase(Txtnumero.Text) = Nothing Then
MessageBox.Show("DIGITE IDENTIFICACION")
Else
If IsNumeric(Txtnumero.Text) = True Then
Btaceptar.Enabled = True
Btaceptar.Focus()
Else
MsgBox("INGRESE SOLO NUMEROS")
Txtnumero.Text = Nothing
Txtnumero.Focus()
End If
End If
End If
End Sub

Private Sub Btaceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btaceptar.Click


Dim Mensaje, Estilo, Ttulo, Respuesta
'AQUI SE ABRE LA CONEXION SOLO PARA ESTE BOTON ES LO NECESARIO
oConn.Open()
'AQUI SE USA OTRA FORMA DE DECLARACION DE VARIABLES PARA EL FORMULARIO
'BUSCAR USUARIOS EN LA TABLA USUARIOS
CMD.CommandText = "select * From EMPLEADOS where identificacion = '" & Txtnumero.Text & "'"
Dim DR As OleDb.OleDbDataReader
CMD.Connection = oConn
DR = CMD.ExecuteReader()
' SI DR EJECUTA UNA LECTURA ENTONCES:
If DR.Read Then
Lbiden.Text = DR(0)
Lbnom.Text = DR(1)
Lbdir.Text = DR(2)
Lbcargo.Text = DR(3)
MsgBox(" BUSQUEDA EXITOSA ", MsgBoxStyle.Information, "RESULTADOS DE LA BUSQUEDA")
Grdatos.Visible = True
Else
'MsgBox("NO ES POSIBLE ENCONTRAR EL ESTUDIANTE" & Chr(13) & " POR SU NUMERO", MsgBoxStyle.Critical, "RESULTADO DE LA
BUSQUEDA")
'Txtnumero.Text = Nothing
'Txtnumero.Focus()
Mensaje = "EL NUMERO BUSCADO NO SE ENCUENTRA" & Chr(13) & "DESEA BUSCAR POR NOMBRES?" ' cuerpo del mensaje.
Estilo = vbYesNo + vbCritical ' Define el estilo, los botones, lo que est despus del mas es el circulo rojo con la cruz.
Ttulo = "ERROR EN DATO" ' es el ttulo.
Respuesta = MsgBox(Mensaje, Estilo, Ttulo) 'el parntesis se pone tambin

If Respuesta = vbYes Then ' El usuario eligi el botn S.


GPNOMBRE.Visible = True
Me.txtnombre.Focus()
Else ' El usuario eligi el botn No.
Me.Hide()
End If
End If
'AQUI SE CIERRA LA CONEXION
oConn.Close()

End Sub

Private Sub Bt2_Click(sender As Object, e As EventArgs) Handles Bt2.Click


Dim Mensaje, Estilo, Ttulo, Respuesta
'AQUI ABRO LA CONEXION SOLO PARA ESTE BOTON ES LO NECESARIO !!!. :D
oConn.Open()

'AQUI SE USA OTRA FORMA DE DECLARACION DE VARIABLES PARA EL FORMULARIO


'BUSCAR USUARIOS EN LA TABLA USUARIOS
CMD.CommandText = "select * From empleados where nombre = '" & txtnombre.Text & "'"
Dim DR As OleDb.OleDbDataReader
CMD.Connection = oConn
DR = CMD.ExecuteReader()
' SI DR EJECUTA UNA LECTURA ENTONCES:
If DR.Read Then
Lbiden.Text = DR(0)
Lbnom.Text = DR(1)
Lbdir.Text = DR(2)
Lbcargo.Text = DR(3)

MsgBox(" BUSQUEDA EXITOSA ", MsgBoxStyle.Information, "RESULTADOS DE LA BUSQUEDA")


Grdatos.Visible = True
Else
'MsgBox("NO ES POSIBLE ENCONTRAR EL ESTUDIANTE" & Chr(13) & " POR SU NUMERO", MsgBoxStyle.Critical, "RESULTADO DE LA
BUSQUEDA")
'Txtnumero.Text = Nothing
'Txtnumero.Focus()
Mensaje = "POR NOMBRE TAMPOCO SE ENCUENTRA " & Chr(13) & "DESEA INGRESARLO AL SISTEMA ?" ' cuerpo del mensaje.
Estilo = vbYesNo + vbCritical ' Define el estilo, los botones, lo que est despus del mas es el circulo rojo con la cruz.
Ttulo = "ERROR EN DATO" ' es el ttulo.
Respuesta = MsgBox(Mensaje, Estilo, Ttulo) 'el parntesis se pone tambin
If Respuesta = vbYes Then ' El usuario eligi el botn S.
Me.Hide()

Else
Me.Close()
End If
End If
'AQUI SE CIERRA LA CONEXION
oConn.Close()
End Sub

End Class

Você também pode gostar