Tutorial Membuat Form Registrasi dan login

 Langkah pertama yaitu membuat Data Base Registrasi nya di MySqlServer management studio

dengan atribut seperti berikut :


Lalu Buka Visual Studio dan membuat project dengan menggunakan bahasa Visual Basic, setelah itu kita meng desaign form yang kita ingin buat Contoh ny seperti punya saya

 Dan ini penggunaan syntax nya:

Imports System.Data.SqlClient

Imports System.Net.Http.Headers

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim con As SqlConnection = New SqlConnection("Data Source=LAPTOP-2FG2PCBN\SQLEXPRESS;Initial Catalog=DB_Regist;Integrated Security=True")

        Dim cmd As SqlCommand = New SqlCommand("insert into TB_Regs values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')", con)

        Dim sda As SqlDataAdapter = New SqlDataAdapter(cmd)

       Dim dt As DataTable = New DataTable()

        sda.Fill(dt)

        MessageBox.Show("Anda Berhasil Mendaftar, Silahkan Login Kembali", "information", MessageBoxButtons.OK, MessageBoxIcon.Information)

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Form2.Show()

        Me.Hide()

    End Sub

End Class


Lalu Buat lah Desaign form ke 2 seperti berikut :

Dan ini Syntax nya :

Imports Microsoft.VisualBasic.ApplicationServices


Public Class Form2

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Try

          If con.State = ConnectionState.Open Then con.Close()

          con.Open()

          Dim sql As String = "select * from TB_Regs where Username= '" & Trim(TextBox1.Text) & "'"

          Dim cmd = New SqlClient.SqlCommand(sql, con)

          Dim rdr As SqlClient.SqlDataReader = cmd.ExecuteReader()

           If rdr.HasRows = False Then

                MsgBox("User Id Tidak Ditemukan!")

                TextBox1.Focus()

            End If

            cmd.Dispose()

            rdr.Close()

            sql = "select * from TB_Regs where Username = '" & Trim(TextBox1.Text) & "' And Password = '" & Trim(TextBox2.Text) & "'"

            cmd = New SqlClient.SqlCommand(sql, con)

            rdr = cmd.ExecuteReader()

            If rdr.HasRows = False Then

                MsgBox("Password Salah!")

                TextBox2.Focus()

                Exit Sub

            Else

                Form3.Show()

                Me.Hide()

            End If

            con.Close()

        Catch ex As Exception

            MsgBox(ex.ToString)

        End Try

    End Sub

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

  End Sub

End Class


Lalu membuat Modul agar tersambung ke Form 2

Imports System.Data.SqlClient

Module Module1

    Dim Constr As String = "Data Source=LAPTOP-2FG2PCBN\SQLEXPRESS;Initial Catalog=DB_Regist;Integrated Security=True"

    Public con As New SqlConnection(Constr)

End Module








Komentar

Postingan populer dari blog ini

Membuat Website Maskapai Penerbangan

PWdPB bab 3

PWDPB Part2