codigo para logear el usuario

Anuncio
CODIGO PARA LOGEAR EL USUARIO
Imports System.Data
Imports System.Data.OleDb
Public Class frmLogin
Dim conexion As New OleDbConnection
Dim comandos As New OleDbCommand
Dim adaptador As New OleDbDataAdapter
Dim lector As OleDbDataReader
Dim consulta As String
Private Sub frmLogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
conexion.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data
source=cefit.accdb"
conexion.Open()
Catch ex As Exception
MsgBox("Error en la conexion", vbCritical, "Sin Conexion")
End Try
End Sub
Private Sub limpiar()
txtUsuario.Clear()
txtcontrasenia.Clear()
txtUsuario.Focus()
End Sub
Private Sub btnIngresar_Click(sender As Object, e As EventArgs) Handles
btnIngresar.Click
consulta = "SELECT usuario, contraseña FROM usuarios WHERE usuario='" &
txtUsuario.Text & "' AND contraseña='" & txtcontrasenia.Text & "'"
comandos = New OleDbCommand(consulta, conexion)
adaptador.SelectCommand = comandos
lector = comandos.ExecuteReader
If lector.HasRows = True Then
MsgBox("Correcto")
limpiar()
frmGuardar.Show()
Me.Hide()
Else
MsgBox("Datos no encontrados")
limpiar()
End If
End Sub
Private Sub btnSalir_Click(sender As Object, e As EventArgs) Handles
btnSalir.Click
conexion.Close()
End
End Sub
End Class
Descargar