cara cara login mengambil data dari database sangat mudah.....
1. kita buka Visual Basic....
2. kita buat di form1 seperti gambar di bawah ini...
=> Lingkaran berwarna Merah itu menggunakan Label
=> Lingkaran berwarna Biru itu menggunakan Textbox
=> Lingkaran berwarna Hitam itu menggunakan commmadbutton
3. Ubah
Label1 == lbluser
Label2 == lblpass
Text1 == txtuser
Text2 == txtpassword
Command1 == cmdlogin
Command2 == cmdexit
4. kita klik double pada gambar yang di silang di bawah ini....
=> Setelah klik double akan masuk ke form1 (code)
Private sub form_load ()
end sub
Hapus Script yang berwarna merah.....
5. lalu kita masukkan Script dibawah ini ke form1 (code)...
Private Sub cmdlogin_Click()
If Cn.State = adStateOpen Then Cn.Close
Cn.Open "Provider=SQLNCLI10;Server=.;Database=rumah;Trusted_COnnection=yes"
If Rs.State = 1 Then Rs.Close
Rs.Open "select * from login where username='" & txtuser.Text & "' And password='" & txtpass.Text & "'", Cn, 3, 3
'Sql = "select * from login where usernama='" & txtuser & "' and password='" & txtpass & "'"
If Not Rs.EOF Then
MsgBox " Login Success "
Else
MsgBox "Username atau Password salah", vbCritical, "L O G I N"
txtuser.Text = ""
txtpass.Text = ""
txtuser.SetFocus
End If
End Sub
Private Sub Form_Load()
End Sub
Private Sub txtuser_Change()
txtuser.SetFocus
End Sub
6. Buatlah Module...
1. kita buka Visual Basic....
2. kita buat di form1 seperti gambar di bawah ini...
=> Lingkaran berwarna Merah itu menggunakan Label
=> Lingkaran berwarna Biru itu menggunakan Textbox
=> Lingkaran berwarna Hitam itu menggunakan commmadbutton
3. Ubah
Label1 == lbluser
Label2 == lblpass
Text1 == txtuser
Text2 == txtpassword
Command1 == cmdlogin
Command2 == cmdexit
4. kita klik double pada gambar yang di silang di bawah ini....
=> Setelah klik double akan masuk ke form1 (code)
Private sub form_load ()
end sub
Hapus Script yang berwarna merah.....
5. lalu kita masukkan Script dibawah ini ke form1 (code)...
Private Sub cmdlogin_Click()
If Cn.State = adStateOpen Then Cn.Close
Cn.Open "Provider=SQLNCLI10;Server=.;Database=rumah;Trusted_COnnection=yes"
If Rs.State = 1 Then Rs.Close
Rs.Open "select * from login where username='" & txtuser.Text & "' And password='" & txtpass.Text & "'", Cn, 3, 3
'Sql = "select * from login where usernama='" & txtuser & "' and password='" & txtpass & "'"
If Not Rs.EOF Then
MsgBox " Login Success "
Else
MsgBox "Username atau Password salah", vbCritical, "L O G I N"
txtuser.Text = ""
txtpass.Text = ""
txtuser.SetFocus
End If
End Sub
Private Sub Form_Load()
End Sub
Private Sub txtuser_Change()
txtuser.SetFocus
End Sub
6. Buatlah Module...
- Klik double pada Form1
- Pilih Add
- Lalu Klik module
- Lalu Open
7. Masukkan Script di bawah ini.....
Option Explicit
Public Cn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public nm As String
Public Sub buka()
If Cn.State = adStateOpen Then Cn.Close
Cn.Open "Provider=SQLNCLI10;Server=.;Database=rumah;Trusted_COnnection=yes"
End Sub
Public Sub eksekusiSQL(SQLstr As String)
Cn.Execute SQLstr
End Sub
Public Sub OpenRecordset(SQLstr As String)
If Rs.State = adStateOpen Then Rs.Close
Rs.Open SQLstr, Cn, adOpenKeyset, adLockOptimistic, adCmdText
End Sub
Public Sub tutup()
If Rs.State = adStateOpen Then Rs.Close
Set Rs.ActiveConnection = Nothing
Set Rs = Nothing
If Cn.State = adStateOpen Then Cn.Close
Set Cn = Nothing
End Sub
8. Jangan Lupa mengaktifkan Microsoft ActiveX Data Objects 2.7 / 2.8
- Klik Project yang di kasih warna...
- Lalu Klik Preferences
- Pilih Microsoft ActiveX Data Objects 2.7 / 2.8 Library
- Klik double di Microsoft ActiveX Data Objects 2.7 / 2.8 Library hingga tercawang
- Klik OK
9. Buatlah database SLQ server 2008
- database kasih nama Login
- Tabel kasih nama Login
- Buat kolom username dan password
- Lalu isi kolom username dan password
10. Save database.....
Semoga anda berhasil................
Kalau masih ada kesalahan/error silakan anda Comment di bawah ini.....
0 komentar:
Posting Komentar