Heloo Masih Nyari Sana sini Koneksi Client Server. Sama Seperti Saya Dulu mencari Koneksi Susah buat di mengerti dari web- web lain. nah akhirnya bisa juga. "Eh Malah Cerita gw.. Hehehehheee" Langsung Aja Sobat sejati Informatika-X. Sekarang Buka Vb.net Kalian, Kita mencoba membuat Form Login Sederhana untuk clien server. tapi kita buat dulu Kopi + Roko. , Ikuti Step By Step Koneksi Di bawah ini @>
- Setelah buka vb.net, Buat New Projek
- buka propertis di sebelah kanan. add new projek, pilih yang Module
- Copy Paste Scriipt Dibawah ini pada Module
Imports System.Data.SqlClient
Module ModKoneksi
'Public Function DbConString() As String
'DbConString = "Data Source=localhost;Integrated Security=SSPI;" & "Initial Catalog=dbEventOrganizer"
'End Function
Public verifikasiuser As String
Public Function Koneksi() As SqlConnection
Dim con As SqlConnection
con = New SqlConnection("Data Source=com; user id=sa; password=cummi;" & "Initial Catalog=proyek2")
Return con
con = Nothing
End Function
Public Function GetRowInfo(ByVal sSql As String) As DataRow
Dim sDa As New SqlDataAdapter(sSql, "Data Source=com; user id=sa; password=cummi;" & "Initial Catalog=proyek2")
Dim Dt As New DataTable
sDa.Fill(Dt)
sDa.Dispose()
If Dt.Rows.Count = 0 Then
Return Nothing
ElseIf Dt.Rows.Count > 1 Then
Throw New Exception("Multiple Rows Afected")
Else
Return Dt.Rows(0)
End If
End Function
End Module
Keterangan Scrip : Ganti Script yang berwarna Merah
- Data Source di dapat dari nama SQL server 2000.. klo ga ngerti liat gambar dibawah, yang ada tanda merah kamu copy ke data source
- User ID tetap sa Dan Password Kamu dapat dari SQL server 2000, klo ga tau lihat di sini saat pertama kali install Sql Server
- Nah yang Catalog itu nama database kalian
step Selanjutnya buka klagi propertis di pojok atas kiri pada vb.net kalian new projek pilih yang FORM
kalo udah masukan Scrip di bawah ini
Imports System.Data.SqlClient
Public Class frmLogin
Dim connect As New SqlConnection
Dim adaptor As New SqlDataAdapter
Dim dtakses As New DataTable
Public Sub refres()
txtUser.Text = ""
txtPwd.Text = ""
End Sub
Private Sub BTnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTnLog.Click
If Me.txtUser.Text = "" Then
MsgBox("User name harus diisi, masukan input yang tepat", MsgBoxStyle.Critical, "Kesalahan")
Me.txtUser.Focus()
Exit Sub
Exit Sub
ElseIf Me.txtPwd.Text = "" Then
MsgBox("Password harus diisi, masukan input yang tepat", MsgBoxStyle.Critical, "Kesalahan")
Me.txtUser.Focus()
Exit Sub
End If
adaptor = New SqlClient.SqlDataAdapter("select * From tb_login where username='" & Me.txtUser.Text & "' and password='" & Me.txtPwd.Text & "'", ModKoneksi.Koneksi)
dtAkses.Clear()
adaptor.Fill(dtakses)
If dtAkses.Rows.Count = Nothing Then
MsgBox("User ID dan Password anda salah, masukan input yang tepat", MsgBoxStyle.Information, "Informasi")
Me.txtUser.Clear()
Me.txtUser.Focus()
Me.txtPwd.Clear()
Exit Sub
Else
Dim hak As String
Dim i As Integer
For i = 0 To (dtAkses.Rows.Count) - 1
hak = dtAkses.Rows(i)("akses")
If hak = "Admin " Then
seting.Show()
Me.Hide()
End If
Next
End If
End Sub
Private Sub BTnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTnExit.Click
Me.Close()
End Sub
End Class
Imports System.Data.SqlClient
Public Class frmLogin
Dim connect As New SqlConnection
Dim adaptor As New SqlDataAdapter
Dim dtakses As New DataTable
Public Sub refres()
txtUser.Text = ""
txtPwd.Text = ""
End Sub
Private Sub BTnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTnLog.Click
If Me.txtUser.Text = "" Then
MsgBox("User name harus diisi, masukan input yang tepat", MsgBoxStyle.Critical, "Kesalahan")
Me.txtUser.Focus()
Exit Sub
Exit Sub
ElseIf Me.txtPwd.Text = "" Then
MsgBox("Password harus diisi, masukan input yang tepat", MsgBoxStyle.Critical, "Kesalahan")
Me.txtUser.Focus()
Exit Sub
End If
adaptor = New SqlClient.SqlDataAdapter("select * From tb_login where username='" & Me.txtUser.Text & "' and password='" & Me.txtPwd.Text & "'", ModKoneksi.Koneksi)
dtAkses.Clear()
adaptor.Fill(dtakses)
If dtAkses.Rows.Count = Nothing Then
MsgBox("User ID dan Password anda salah, masukan input yang tepat", MsgBoxStyle.Information, "Informasi")
Me.txtUser.Clear()
Me.txtUser.Focus()
Me.txtPwd.Clear()
Exit Sub
Else
Dim hak As String
Dim i As Integer
For i = 0 To (dtAkses.Rows.Count) - 1
hak = dtAkses.Rows(i)("akses")
If hak = "Admin " Then
seting.Show()
Me.Hide()
End If
Next
End If
End Sub
Private Sub BTnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTnExit.Click
Me.Close()
End Sub
End Class
Jika sudah Di paste Kalian Save dengan nama frmLogin.vb
Kalian Runing Program Vb. Tersebut, Apabila Masih Eror Kalian Berusahalah sendiri Jika Kalian Masi Mentok Untuk Berfikir Kalian Curhat di YM adimuwardi@yahoo.com
0 komentar:
Posting Komentar