HOME

HOME

Online voting system in vb.net and sql SSMS







CODE OF FORM2


Public Class Form2

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click

    End Sub

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

        Dim a As String = "admin"

        Dim b As String = "pass"

        If (TextBoxUserid.Text = a And b = TextBoxpassword.Text And RadioButton1.Checked) Then

            MsgBox("Login success")

            Me.Hide()

            Dim r As New Form1

            r.Show()

        ElseIf (TextBoxUserid.Text = a And b = TextBoxpassword.Text And RadioButton2.Checked) Then

            MsgBox("Login success")

            Me.Hide()

            Dim r As New Form5

            r.Show()

        Else

            MsgBox("login failed")

            TextBoxUserid.Text = ""

            TextBoxpassword.Text = ""

        End If

    End Sub

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

    End Sub

End Class



This is form1 of the project as 2nd form to open up







CODE OF FORM1

Imports System.Data.SqlClient

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs)

    End Sub

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

    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs)

    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

    End Sub

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

        Me.Hide()

        Dim r As New Form3

        r.Show()

    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click

        Me.Hide()

        Dim r As New Form4

        r.Show()

    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs)

        Me.Hide()

        Dim r As New Form5

        r.Show()

    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

        Me.Hide()

        Dim r As New Form6

        r.Show()

    End Sub

    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click

    End Sub

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

        Me.Hide()

        Dim r As New Form2

        r.Show()

    End Sub

End Class


This is form3 of the project as 3rd form to open up







CODE OF FORM3

Imports System.Data.SqlClient

Public Class Form3

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

        Dim con As SqlConnection = New SqlConnection("Data Source=DESKTOP-FAG6TBF;Initial Catalog=studentdata;Integrated Security=True")

        Dim cmd As SqlCommand = New SqlCommand("INSERT INTO [dbo].[studentdata]

           ([name]

           ,[class]

           ,[rollno]

           ,[email])

     VALUES

           ('" + TextBox1.Text + "','" + ComboBox1.SelectedItem.ToString() + "','" + TextBox2.Text + "','" + TextBox3.Text + "')", con)

        con.Open()

        cmd.ExecuteNonQuery()

        MsgBox("! YOUR ROLL NO IS YOUR VOTING Id", vbExclamation + vbInformation, "you have registered succesfully")

        con.Close()

        TextBox1.Text = ""

        TextBox2.Text = ""

        TextBox3.Text = ""

        ComboBox1.Text = ""

    End Sub

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

    End Sub

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

        Me.Hide()

        Dim r As New Form1

        r.Show()

    End Sub

End Class


This is form4 of the project as 4th form to open up







CODE OF FORM4

Imports System.Data.SqlClient

Public Class Form4

    Private Sub Form4_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=DESKTOP-FAG6TBF;Initial Catalog=candidates data;Integrated Security=True")

        If (ComboBox1.Text = "president") Then

            Dim cmd As SqlCommand = New SqlCommand("INSERT INTO [dbo].[candidate data]

           ([name]

           ,[class]

           ,[roll no]

           ,[Political Party Name]

           ,[Nomination post])

     VALUES

           ('" + TextBox1.Text + "','" + ComboBox2.SelectedItem.ToString + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + ComboBox1.SelectedItem.ToString() + "')", con)

            con.Open()

            cmd.ExecuteNonQuery()

            MsgBox("you have registered succesfully")

            con.Close()

        Else

            Dim cm As SqlCommand = New SqlCommand("INSERT INTO [dbo].[vice president database]

           ([name]

           ,[class]

           ,[roll no]

           ,[political party name]

           ,[nomination post])

            VALUES

           ('" + TextBox1.Text + "','" + ComboBox2.SelectedItem.ToString + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + ComboBox1.SelectedItem.ToString() + "')", con)

            con.Open()

            cm.ExecuteNonQuery()

            MsgBox("you have registered succesfully")

            con.Close()

        End If

        TextBox1.Text = ""

        ComboBox2.Text = ""

        TextBox3.Text = ""

        TextBox4.Text = ""

        ComboBox1.Text = ""

    End Sub

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

        Me.Hide()

        Dim r As New Form1

        r.Show()

    End Sub

End Class


This is form5 of the project as 5th form to open up







CODE OF FORM5

Imports System.Data.SqlClient

Public Class Form5

    Dim a As Integer = 0

    Dim s, c, d As Integer

    Dim con As SqlConnection = New SqlConnection("Data Source=DESKTOP-FAG6TBF;Initial Catalog=candidates data;Integrated Security=True")

    Dim can As SqlConnection = New SqlConnection("Data Source=DESKTOP-FAG6TBF;Initial Catalog=studentdata;Integrated Security=True")

    Dim adapter As New SqlDataAdapter("SELECT [id]

      ,[name]

      ,[class]

      ,[roll no]

      ,[Political Party Name]

      ,[Nomination post]

  FROM [candidate data]", con)

    Dim table As New DataTable()

    Dim t1 As New DataTable()

    Dim tale As New DataTable()

    Dim adpt As New SqlDataAdapter("SELECT [id]

      ,[name]

      ,[class]

      ,[roll no]

      ,[political party name]

      ,[nomination post]

  FROM [dbo].[vice president database]", con)

    Dim adp As New SqlDataAdapter("SELECT [name]

      ,[class]

      ,[rollno]

      ,[email]

  FROM [dbo].[studentdata]", can)

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

        Me.Hide()

        Dim r As New Form2

        r.Show()

        con.Close()

    End Sub

    Public Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        adapter.Fill(table)

        ComboBox1.DataSource = table

        ComboBox1.DisplayMember = "name"

        adpt.Fill(t1)

        ComboBox2.DataSource = t1

        ComboBox2.DisplayMember = "name"

        adp.Fill(tale)

        ComboBox3.DataSource = tale

        ComboBox3.DisplayMember = "rollno"

    End Sub

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

        Dim ab = ComboBox1.Text

        Dim bc = ComboBox2.Text

        Dim con As SqlConnection = New SqlConnection("Data Source=DESKTOP-FAG6TBF;Initial Catalog=candidates data;Integrated Security=True")

        Dim com As New SqlCommand("INSERT INTO [dbo].[vote data]

           ([president]

           ,[vice president])

     VALUES

           ('" + ab + "','" + bc + "')", con)

        con.Open()

        com.ExecuteNonQuery()

        MsgBox("vote submitted succesfully")

        Me.Hide()

        Dim r As New Form2

        r.Show()

        con.Close()

    End Sub

End Class











CODE OF FORM6

Imports System.Data.SqlClient


Public Class Form6

    Dim con, con1, conw As SqlConnection

    Dim adpt, adpt1 As New SqlDataAdapter

    Dim com, com1, com2 As New SqlCommand

    Dim t1 As New DataTable

    Dim t2 As New DataTable

    Dim bind, bind1 As New BindingSource

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

        conx()

        Try

            con.Open()

            Dim query As String

            query = "select president,count(*)  from [vote data] group by [president] "

            com = New SqlCommand(query, con)

            adpt.SelectCommand = com

            adpt.Fill(t1)

            bind.DataSource = t1

            DataGridView1.DataSource = bind

            adpt.Update(t1)

            Dim reader As SqlDataReader = com.ExecuteReader

            Dim sum As Integer

            While reader.Read

                sum += reader(1)

            End While

            Dim reader1 As SqlDataReader = com.ExecuteReader

            While reader1.Read

                If reader1(0) = "president1" Then

                    MsgBox("president1" & "is winner")

                Else

                    MsgBox("president2" & "is winner")

                End If

            End While

            con.Close()

        Catch ex As Exception

        End Try

        conex()

        Try

            con1.Open()

            Dim query1 As String

            query1 = "select [vice president],count(*)  from [vote data] group by [vice president]  "

            com1 = New SqlCommand(query1, con1)

            adpt1.SelectCommand = com1

            adpt1.Fill(t2)

            bind1.DataSource = t2

            DataGridView2.DataSource = bind1

            adpt1.Update(t2)

            Dim reader3 As SqlDataReader = com1.ExecuteReader

            Dim sum1 As Integer

            While reader3.Read

                sum1 += reader3(1)

            End While

            Dim reader4 As SqlDataReader = com1.ExecuteReader

            While reader4.Read

                If reader4(0) = "president1" Then

                    MsgBox("president1" & "is winner")

                Else

                    MsgBox("president2" & "is winner")

                End If

            End While

            con1.Close()

        Catch ex As Exception

        End Try

    End Sub

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

        Me.Hide()

        Dim r As New Form1

        r.Show()

    End Sub

    Private Sub conx()

        con = New SqlConnection

        con.ConnectionString = "Data Source=DESKTOP-FAG6TBF;Initial Catalog=candidates data;Integrated Security=True"

    End Sub

    Private Sub conex()

        con1 = New SqlConnection

        con1.ConnectionString = "Data Source=DESKTOP-FAG6TBF;Initial Catalog=candidates data;Integrated Security=True"

    End Sub

    Private Sub cone()

        conw = New SqlConnection

        conw.ConnectionString = "Data Source=DESKTOP-FAG6TBF;Initial Catalog=candidates data;Integrated Security=True"

    End Sub

End Class

DATABASE

Form4 database for president post , table name= candidate data





Form4 database for vice presidnet post, table name = vice president database




Form5 storage database for voote and Form6 database to retrive result table name = vote data



Form3 database for voters , table name= student data










To download the pdf of this project Click Here


Project description






This is from 2 of the project as first form to open up

No comments:

Post a Comment