Cara Membuat Form Login pada VB.Net dengan Mysql Database
Cara Membuat Form Login pada VB.Net dengan Mysql Database mungking coding yang ane kasih bisa bantu, langsung saja ane kasing listingnya :
Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Imports MySql.Data.MySqlClient
Public Class Login
Public passlama As String = “”
Public userlogin As String = “”
Public levelku As String = “”
Sub formKosongLogin()
txtUsername.Text = “”
txtPassword.Text = “”
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUsername.KeyPress
If e.KeyChar = Chr(13) Then txtPassword.Focus()
End Sub
Public passlama As String = “”
Public userlogin As String = “”
Public levelku As String = “”
Sub formKosongLogin()
txtUsername.Text = “”
txtPassword.Text = “”
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUsername.KeyPress
If e.KeyChar = Chr(13) Then txtPassword.Focus()
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPassword.KeyPress
If e.KeyChar = Chr(13) Then Button1.Focus()
End Sub
If e.KeyChar = Chr(13) Then Button1.Focus()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If txtUsername.Text = “” Then
MsgBox(“Username Tidak Boleh Kosong”, MsgBoxStyle.Critical)
txtUsername.Focus()
ElseIf txtPassword.Text = “” Then
MsgBox(“Password Tidak Boleh Kosong”, MsgBoxStyle.Critical)
txtPassword.Focus()
Else
Call cekkoneksi()
Dim sqlQuery As String = ” SELECT * FROM user WHERE username = ‘” & txtUsername.Text & “‘ AND password = ‘” & txtPassword.Text & “‘”
Dim user As String = “”
Dim pass As String = “”
Dim level As String = “”
Dim myData As MySqlDataReader
Dim sqltable As New DataTable
If sConnection.State = ConnectionState.Closed Then
sConnection.ConnectionString = serper
sConnection.Open()
End If
If txtUsername.Text = “” Then
MsgBox(“Username Tidak Boleh Kosong”, MsgBoxStyle.Critical)
txtUsername.Focus()
ElseIf txtPassword.Text = “” Then
MsgBox(“Password Tidak Boleh Kosong”, MsgBoxStyle.Critical)
txtPassword.Focus()
Else
Call cekkoneksi()
Dim sqlQuery As String = ” SELECT * FROM user WHERE username = ‘” & txtUsername.Text & “‘ AND password = ‘” & txtPassword.Text & “‘”
Dim user As String = “”
Dim pass As String = “”
Dim level As String = “”
Dim myData As MySqlDataReader
Dim sqltable As New DataTable
If sConnection.State = ConnectionState.Closed Then
sConnection.ConnectionString = serper
sConnection.Open()
End If
With sqlCommand
.CommandText = sqlQuery
.Connection = sConnection
End With
.CommandText = sqlQuery
.Connection = sConnection
End With
With sqlAdapter
.SelectCommand = sqlCommand
.Fill(sqltable)
End With
.SelectCommand = sqlCommand
.Fill(sqltable)
End With
‘simpan password lama buat diambil ke menu utama
myData = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection)
myData.Read()
myData.Read()
If myData.HasRows = True Then
Me.Visible = False
FormUtama.Show()
FormUtama.Panel1.Text = myData.Item(“kd_user”)
FormUtama.Panel2.Text = myData.Item(“nm_user”)
FormUtama.Panel3.Text = myData.Item(“username”)
Penjualan.txtKasir.Text = myData.Item(“nm_user”)
myData.Close()
Else
MsgBox(“User/Password tidak ada”, MsgBoxStyle.Critical)
txtUsername.Focus()
End If
myData.Dispose()
myData.Close()
End If
Call formKosongLogin()
txtUsername.Focus()
FormUtama.Show()
FormUtama.Panel1.Text = myData.Item(“kd_user”)
FormUtama.Panel2.Text = myData.Item(“nm_user”)
FormUtama.Panel3.Text = myData.Item(“username”)
Penjualan.txtKasir.Text = myData.Item(“nm_user”)
myData.Close()
Else
MsgBox(“User/Password tidak ada”, MsgBoxStyle.Critical)
txtUsername.Focus()
End If
myData.Dispose()
myData.Close()
End If
Call formKosongLogin()
txtUsername.Focus()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End
End Sub
Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call cekkoneksi()
Call cekkoneksi()
End Sub
End Class
End Class