Como crear un login vb.net y sqlserver

Código básico.

Imports System.Data.SqlClient
Imports System.IO

Public Class LoginForm1
    

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim conexion As New SqlConnection(TextBox1.Text)
        Dim command As New SqlCommand("select * from Users where Username = @Username and User_Pass = @User_Pass", conexion)
        command.Parameters.Add("@Username", SqlDbType.VarChar).Value = UsernameTextBox.Text
        command.Parameters.Add("@User_Pass", SqlDbType.VarChar).Value = PasswordTextBox.Text
        Dim adapter As New SqlDataAdapter(command)
        Dim table As New DataTable()
        adapter.Fill(table)
        If table.Rows.Count() <= 0 Then

            MessageBox.Show("Username Or Password Are Invalid")

        Else

            MessageBox.Show("Login Successfully")

            Dim frm As New Admin

            Me.Hide()

            frm.Show()

        End If
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub LoginForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Dim lic As New StreamReader("\Cone.txt")
            TextBox1.Text = lic.ReadLine
        Catch ex As Exception
            MsgBox("La conexion aun no a sido creada porfavor configurar")
        End Try


    End Sub

    Private Sub UsernameLabel_Click(sender As Object, e As EventArgs) Handles UsernameLabel.Click

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Conexionfrm.Show()
    End Sub
End Class
Compartir En Redes Sociales

Deja un comentario