2/8/19

VB.NET DB Connectivity Coding Reference part - 5 | Login user account

Previous post we have learned 
VB.NET Database Connectivity Coding Reference part - 1 | Database Connection
VB.NET DB Connectivity Coding Reference part - 2 | CRUD & Navigation Operation.
VB.NET DB Connectivity Coding Reference part - 4 | List Box, Combo Box View the Data

In this post, We're going to learn how to List Box, Combo Box View the Data.
This tutorial have one file.
1. FormLogin

FromLogin (Design View):





FromLogin (Code View):

Imports System.Data.SqlClient
Public Class FormLogin

    Dim SqlConn As New SqlConnection("Server=Najathi\SQLEXPRESS;Database=Student;Integrated Security=True")

    Private Sub ButtonLogin_Click(sender As Object, e As EventArgs) Handles ButtonLogin.Click

        Dim sqlCmd As New SqlCommand("SELECT * FROM Login WHERE Username=@user AND Password=@pass", SqlConn)

        sqlCmd.Parameters.Add("@user", SqlDbType.VarChar).Value = TextBoxUsername.Text
        sqlCmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = TextBoxPassword.Text

        Dim sqlDA As New SqlDataAdapter(sqlCmd)
        Dim dt As New DataTable()

        sqlDA.Fill(dt)

        If dt.Rows.Count() <= 0 Then
            MessageBox.Show("Username or Password Wrong!")
        Else
            MessageBox.Show("Login Succefully!")

            Dim frm As New FormNavigation
            frm.Show()
            Me.Hide()

        End If

    End Sub

    Private Sub ButtonCancel_Click(sender As Object, e As EventArgs) Handles ButtonCancel.Click
        Me.Close()
    End Sub
End Class

No comments:

Post a Comment

About

Hi, I'm Najathi.
I've started entrepreneurial company, Twin Brothers.Inc.
One is self-funded & the other is venture backed. I also send a weekly. where I share relevent, curated links.

Every Week I Publish a short post on writing, publishing, or content of IT Related

Contact Form

Name

Email *

Message *