Membuat Form Login Pada VB.Net ( Database SQL Server )
Sebelum membaca tutorial login pada vb.net maka terlebih dahulu buatlah database login dan koneksi, yang belum mengetahui harap baca postingan sebelumnya.
Bagi yang udah paham silahkan simak tutorial di bawah ini .
Semua koding :
Imports System.Data
Imports System.Data.SqlClient
Imports System.Security.SecurityException
Public Class login
Dim Conn As New SqlConnection(WindowsApplication1.My.Settings.db1ConnectionString)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlQRY As String = "SELECT * FROM login_system WHERE pengguna= '" & Me.TextBox1.Text & "' AND Password= '" & Me.TextBox2.Text & "'"
Dim cmd As SqlCommand = New SqlCommand(sqlQRY, Conn)
'create data reader
Dim rdr As SqlDataReader = cmd.ExecuteReader
rdr.Read()
If rdr.HasRows = True Then
Dim Username As String = rdr("pengguna").ToString
Dim Password As String = rdr("Password").ToString
MsgBox("Username dan password benar", , "")
splash.Show()
Me.Hide()
Else
MessageBox.Show("Invalid Password or Username", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Sub
Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
' Open connection
conn.Open()
Catch ex As SqlException
MessageBox.Show(ex.Message, "Error..", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
' Close connection
'conn.Close()
End Try
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End Class
Semoga Bermanfaat
0 comments:
Post a Comment