Creacion Login en VB

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Antes De iniciar Se debe crear en SQL los siguientes elementos para la

creacion del Login en Visual Basic:

Crear en Sql Server

Create database tester11

Use tester11

Create table TBL_USUARIO


(
codigo int, USUARIO varchar(30), Clave varchar(30)
)
Insert into TBL_USUARIO values (1,'stewart','123456')
Insert into TBL_USUARIO values (2,'swyter','1234')
_________________________________________________________________________

Diseños
Agregar otro form para el menu

Public Class FrmMenuPrincipal

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Application.Exit()

End Sub
_________________________________________________________________________

Private Sub FrmMenuPrincipal_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
ToolTip1.SetToolTip(me.Button1, "puedes salir por favor?")
End Sub
End Class

_________________________________________________________________________
Login vb OK

Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlCommand
_________________________________________________________________________
DOBLE CLICK AL BOTON1 “BTNACEPTAR”

Public Class Form1

Private Sub BTNACEPTAR_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles BTNACEPTAR.Click

Dim conn As New SqlClient.SqlConnection("Data


Source=INGFREDDYSANTOS\SQLEXPRESS;Initial Catalog=tester12;Integrated Security=True")
Dim dr As SqlDataReader
'Dim da As SqlDataAdapter
Dim ds As New DataSet
'Dim dt As DataTable

Try
conn.Open()
Dim cmd As New SqlCommand("Select * from TBL_USUARIO where USUARIO='" &
Me.TextBox1.Text & "'" & " and Clave='" & Me.TextBox2.Text & "'", conn)
dr = cmd.ExecuteReader
If (dr.HasRows = True) Then
MessageBox.Show("BIENVENIDO A NUESTRO SISTEMA ESCOLAR")
Me.Hide()
FOrmMENU.Show()

ElseIf (dr.HasRows = False) Then


MessageBox.Show("NOMBRE DE USUARIO O CLAVE NO EXISTE")
TextBox1.Clear()
TextBox2.Clear()
TextBox1.Focus()
End If
Catch Exoledb As Exception
Finally
conn.Close()
End Try

End Sub
End Class
_________________________________________________________________________

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
Me.ToolTip1.SetToolTip(Me.BTNSALIR, "puedes salir por favor?")
End Sub
_________________________________________________________________________
Private Sub BTNSALIR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles BTNSALIR.Click
Application.Exit()
End Sub
End Class
_________________________________________________________________________
CASO? IMPRIME

CASO? IMPRIME

You might also like