Senin, 11 Juli 2016

Membuat Form Login di Visual Basic

Berikut ini adalah kode dan tutorial yang disertai video bagaimana cara membuat form login menggunakan Visual Basic VB.NET. Dalam tutorial saya menggunakan 2 form dan 1 module/class.
Kode Koneksi:

Imports MySql.Data.MySqlClient
Public Class koneksidata
    Dim conect As New MySqlConnection("server=localhost;user=root;password='';database='dblogin'")
    Public Function open() As MySqlConnection
        Try
            conect.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return conect
    End Function
    Public Function close() As MySqlConnection
        Try
            conect.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return conect
    End Function
End Class
Kode Form1/Form Login:

Imports MySql.Data.MySqlClient
Public Class Form1
#Region "deklarasi"
    Dim mycmd As New MySqlCommand
    Dim myconnection As New koneksidata
    Dim objadapter As MySqlDataAdapter
    Dim objreader As MySqlDataReader
    Dim dtable As New DataTable
#End Region
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        objadapter = New MySqlDataAdapter("select username,password from tabellogin where username='" & Replace(TUSER.Text, "'", "''") & "' and password='" & Replace(TPASS.Text, "'", "''") & "'", myconnection.open)
        dtable.Clear()
        objadapter.Fill(dtable)
        If dtable.Rows.Count = Nothing Then
            MsgBox("Gagal Login !!")
        Else
            Form_Profil.Show()
            Me.Hide()
        End If
        myconnection.close()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TUSER.Text = ""
        TPASS.Text = ""
    End Sub
End Class
Kode Form Profil:

Public Class Form_Profil
    Private Sub Form_Profil_Disposed(sender As Object, e As EventArgs) Handles Me.Disposed
        End
    End Sub
End Class

Download Project:
Download Project
Lihat Video:

0 komentar:

Posting Komentar

Kita bukanlah apa-apa tanpaNya, jika ada pertanyaan mengenai artikel silakan tinggalkan komentar anda melalui form komentar :)

SkyArs Corp. © 2016. Tweaked by: Soni Sitez Powered by: Blogger