Powered By Blogger

Kamis, 09 Juni 2011

login

• Membuat login pada VB.net
• Klik kanan pada project yang dibuat
• Add -> New item-> login form



• Klik 2x pada tombol ok
• Masukan sintax
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
If UsernameTextBox.Text = "robby" And PasswordTextBox.Text = "ganteng" Then
MDIParent1.Show()
Me.Visible = False
Else
MsgBox("login gagal,coba ulangi lagi")
End If
End Sub
* Lalu jalankan / running program tersebut
* Masukan username “robby” dan password “ganteng”


• Jika sudah bisa login dan muncul MDI Parent Form maka Login telah selesai.

vb3


Public Class Form2
Sub kosong()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End Sub
Sub netral()
Button1.Text = "Tambah"
Button2.Text = "Ubah"
Button3.Text = "Hapus"
Button4.Text = "Keluar"
Button1.Enabled = True 'enable=funsi aktif/tdaknya sebuah objek
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
End Sub
Sub celrecord()
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then ''ada atau tidak recod yg dimaksukkan
hasilcek = True
Else
hasilcek = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call simpankelompok()
End Sub
Sub simpankelompok()
If Button1.Text = "Tambah" Then
TextBox1.Text = ""
Button1.Text = "Simpan"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
TextBox1.Focus()
Else
If TextBox1.Text = "" Then Exit Sub ''then exit sub = keluar dari sub class dgan syarat textbox harus diisi/pengecekan validasi
If TextBox2.Text = "" Then Exit Sub
Call celrecord()
Try
If hasilcek = "False" Then
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Insert into Jurusan (kdjur,nmjur)values ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
tampil2.ExecuteNonQuery()
Call kosong()
Else
MsgBox("Data sudah ada , silahkan cek data yang akan diinput ", MsgBoxStyle.Critical, "Input data") ''critical = ! dalam msgbox
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If

vb2

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call bukakoneksi()

End Sub
Sub Jurusan()
Call bukakoneksi()
Tampil2.Connection = database
Tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil2.ExecuteReader

If Tampilkan.HasRows = True Then
While Tampilkan.Read()
If IsDBNull(tampilkan("kdjur")) Then
Else
TextBox2.Text = tampilkan("nmjur")
End If
End While
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call Jurusan()

End Sub
End Class

vbkoneksi

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call bukakoneksi()

End Sub
Sub Jurusan()
Call bukakoneksi()
Tampil2.Connection = database
Tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from jurusan where kdjur='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil2.ExecuteReader

If Tampilkan.HasRows = True Then
While Tampilkan.Read()
If IsDBNull(tampilkan("kdjur")) Then
Else
TextBox2.Text = tampilkan("nmjur")
End If
End While
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call Jurusan()

End Sub
End Class