This Blog is composed of how to create a program in Visual Studio.

How to Create a Simple Log-In that have Database

How to create a simple Log-In that have Database



1st Step: Create Design.
                                           

Ø  Drag a label, textbox and button onto the form and change the label TEXT and NAME in properties.
o   For Number:
§  1. => change the label text into “User Name:”
§  2. => change the label text into “Password”
§  3. => change the textbox name into “txtUserName”
§  4. => change the textbox name into “Password”
§  5. => change the button text into “LogIn” and button name into “btnLogIn”


2nd Step: Create Database.
Ø      Steps on how to create a database
o   Open any Microsoft Office Access
o   Click Blank Database
o   Change file Name into DBAcount(any DB file name)
o   Click Create
o   Right Click Table1
o   Click Design View
o   Create table name(ex: tblAcount)
o   Click Ok
o   Create a Primary Key(ex: User_ID) with the Data type (ex: “AutoNumber”)
o   Create attribute (ex: UserName and Password) with the Data type (ex: Text)
o   Input Value for the UserName and Password
o   Close tblAcount
3rd Step: Create Module for the Database Connection
Ø  Steps on how to Create a Module
o   Go to Project
o   Click Add Module
o   Change Name(ex: ModConnection)
o   Click Add
o   Start Coding
§  Import sytem data Oledb
·         Imports System.Data.OleDb
§  Inside the ModConnection
§  Create a Public Variable Name for the New OledbCommand(ex: mycommand)
·         Public mycommand As New OleDbCommand
§  Create a Public Variable Name for the OleDbDataReader(ex: mysqleader)
·         Public mysqlreader As OleDbDataReader
§  Create a Public Variable Name for the OleDbDataAdapter(ex: myAdapter)
·         Public myadapter As New OleDbDataAdapter
§  Create a Public Variable Name for the New DataSet(ex: myDataSet)
·         Public mydataset As New DataSet
§  Create a Public Variable Name for the New DataTable(ex: myDataTable)
·         Public mydataTable As New DataTable
§  Create a Public Variable Name “sqlState”
·         Public sqlState As String
§  Create a Public Variable Name for the OlebDb.OlebdbConnection(ex: conn)
·             Public conn As OleDb.OleDbConnection = getConnection()
§  Create a Public Function name for OleDb.OleDbConnection (ex: getConnection)
·         Public Function getConnection() As OleDb.OleDbConnection
·         Inside the Public Function get your database name
o   Ex. Return New OleDb.OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0; Data Source=" & Application.StartupPath & "\DATABASE" & "\DBAcount.accdb")

4th Step: Start Coding for the Log-In Form

    Public Class LogIn
    Dim pass, user As String

    Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogIn.Click
        VerifyAcount()
    End Sub

    Private Sub VerifyAcount()

        Try
            sqlState = "SELECT UserName,Password from tblAcount where UserName='" & txtUserName.Text & "'and Password='" & txtPassword.Text & "'"
            conn.Open()
            mycommand = conn.CreateCommand
            mycommand.CommandText = sqlState
            myadapter.SelectCommand = mycommand
            myadapter.Fill(mydataset, "tblAcount")
            mydataTable = mydataset.Tables("tblAcount")
            mysqlreader = mycommand.ExecuteReader
            While mysqlreader.Read
                pass = mysqlreader("Password")
                user = mysqlreader("UserName")
            End While


            If pass = txtPassword.Text And user = txtUserName.Text Then
                MsgBox("Log-In Succesdully!")

            Else
                MsgBox("Invalid Password And UserName")
            End If

        Catch ex As Exception
            MsgBox("" & ex.Message)
        End Try
        conn.Close()
    End Sub

 
End Class


5th Step: Run the Program

                             Ø  Click to start Debugging Button (F5).
                
                            







Share:

No comments:

Post a Comment

About Me

My photo
Pagadian City, IX, Philippines

Followers

Social Profiles

Follow us

Keyboard

USB Drive

Total Pageviews