Programming for Everybody: visual Basic.net programmer Registration Form in VB.net

visual Basic.net programmer Registration Form in VB.net



Imports System.IO

Imports System.Data.SqlClient

Public Class Form1

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

        If CheckBox1.Checked = True Then

            password.UseSystemPasswordChar = False

        Else

            password.UseSystemPasswordChar = True

        End If

    End Sub


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

        OpenFileDialog1.ShowDialog()

        image_path.Text = Path.GetDirectoryName(OpenFileDialog1.FileName) & "\" & Path.GetFileName(OpenFileDialog1.FileName)

        PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)

    End Sub


    Private Sub lastname_KeyDown(sender As Object, e As KeyEventArgs) Handles lastname.KeyDown

        If e.KeyCode = Keys.Enter Then

            username.Text = firstname.Text + lastname.Text

        End If

    End Sub


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

        If username.Text = "" Then

            MessageBox.Show("Please enter username")

            Return

        End If

        If m1.Checked = False And f1.Checked = False Then

            MessageBox.Show("Please select gender")

            Return

        End If

        Dim conn As New SqlConnection("Data source=.;initial catalog=register2;integrated security=true")

        If conn.State = ConnectionState.Closed Then

            conn.Open()

        End If

        Dim cmd As New SqlCommand("Select username from table1 where username=@username", conn)

        cmd.Parameters.AddWithValue("username", username.Text)

        Dim myreader As SqlDataReader = cmd.ExecuteReader

        If (myreader.Read()) Then

            MessageBox.Show("Username inserted before")

            conn.Close()

            Return

        Else

            conn.Close()


            Dim cmd2 As New SqlCommand("Insert into table1(firstname,lastname,username,password,phone,date_birth,gender,image1)Values(@firstname,@lastname,@username,@password,@phone,@date_birth,@gender,@image1)", conn)

            cmd2.Parameters.AddWithValue("firstname", firstname.Text)

            cmd2.Parameters.AddWithValue("lastname", lastname.Text)

            cmd2.Parameters.AddWithValue("username", username.Text)

            cmd2.Parameters.AddWithValue("password", password.Text)

            cmd2.Parameters.AddWithValue("phone", phone.Text)

            cmd2.Parameters.AddWithValue("date_birth", date_birth.Text)



            Dim gender_v As Boolean

            If m1.Checked = True Then

                gender_v = 1

            End If

            If f1.Checked = True Then

                gender_v = 0

            End If


            cmd2.Parameters.AddWithValue("gender", gender_v)

            cmd2.Parameters.AddWithValue("image1", image_path.Text)


            If conn.State = ConnectionState.Closed Then

                conn.Open()

            End If

            cmd2.ExecuteNonQuery()

            conn.Close()

            MessageBox.Show("Data inserted Successfully")

        End If

    End Sub

End Class

 

No comments:

Post a Comment