- Buka vb.net 2008 anda
- kemudian buat tampilan seperti gambar di atas
- Kemudian isikan nama di button dan label sbg:
Passwordàtxtpassword
Masukàbtnmasuk
Batalàbtnbatal
Keluaràbtnkeluar
- kemudian klik 2 kali pada form tersebut
- Lalu masukan koding di dalamnya sbg berikut:
Imports MySql.Data.MySqlClient
Public
Class frmlogin
Class frmlogin
Dim kon As
New MySqlConnection(strkon)
Dim perintah As
New MySqlCommand
Dim cek As MySqlDataReader
Private
Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
If MsgBox("Apakah Anda Yakin ?", 4 + 32 + 256, "Pesan") = MsgBoxResult.Yes Then
Me.Close()
End If
End Sub
Private
Sub btnmasuk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmasuk.Click
Sub btnmasuk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmasuk.Click
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "SELECT * from tbuser where " _
& "Nmuser='" & txtuser.Text & "' and pass='" & txtpassword.Text & "'"
'userpass=MD5('" & txtpassword.Text & "')and username='" & txtuserid.Text & "'"
cek = perintah.ExecuteReader
cek.Read()
If cek.HasRows Then
frmutama.Show()
Me.Hide()
Else
MsgBox("MAAF, User dan Password Salah")
End If
cek.Close()
kon.Close()
txtpassword.Text = ""
End Sub
Private
Sub btbatal_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
Sub btbatal_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
txtuser.Clear()
txtpassword.Clear()
txtuser.Focus()
End Sub
Private
Sub txtuser_KeyDown(ByVal sender As
Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtuser.KeyDown
Select
Case e.KeyCode
Case Keys.Enter
txtpassword.Focus()
End Select
End Sub
Private
Sub txtpassword_KeyDown(ByVal sender As
Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtpassword.KeyDown
Sub txtpassword_KeyDown(ByVal sender As
Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtpassword.KeyDown
Select
Case e.KeyCode
Case Keys.Enter
btnmasuk.Focus()
End Select
End Sub
End Class
- Kemudian buat modul supaya bisa terkoneksi dengan mysql
- Klik project
- Klik add module
- Lalu masukan koding di bawah ini ,di dalam modul tersebutImports MySql.Data.MySqlClient.MySqlConnection
Module Module1
Public strkon As
String = "Server=localhost;user id=root@localhost;password=root;database=dbdealer"
End
Module
NB :kode yang berwarna merah tersebut ganti dengan user dan password di server mysql anda,kemudian databasenya jangan lupa sesuai data base anda masing masing.
{ 0 comments... read them below or add one }
Post a Comment