2 Replies - 154 Views - Last Post: 14 December 2018 - 07:48 PM Rate Topic: -----

#1 ajucarat   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-December 18

Voting System, counting the total votes for each registered candidates

Posted 14 December 2018 - 12:07 PM

so i am creating an election application for my final project...and im stuck at counting the voters that i have saved on ms access database and displaying the total votes for each previously signed up candidates in the No of Votes(Nov) Textbox..here is my code for the total votes form
 

Option Explicit On
Imports System.Data.OleDb

Public Class Total
    Dim dbconn As New OleDb.OleDbConnection
    Dim adt As New OleDbDataAdapter
    Dim ds As New DataSet
    Dim myCommand As New OleDb.OleDbCommand
    Dim myReader As OleDbDataReader
    Dim query As String

    Private Sub Total_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        dbconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\AL\Documents\Final Project\VP\ElectionDb.accdb"
        dbconn.Open()
        Me.fillcombo()

    End Sub

    Function fillcombo()
        query = "SELECT * FROM Sign_Up"
        myCommand.CommandText = query
        myCommand.Connection = dbconn
        myReader = myCommand.ExecuteReader
        While (myReader.Read())
            CanComboBox.Items.Add(myReader("CandidateNumber"))
        End While
        myCommand.Dispose()
        myReader.Close()

    End Function

    Private Sub CanComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CanComboBox.SelectedIndexChanged
        Using myCommand As New OleDbCommand("SELECT * FROM Sign_Up WHERE [email protected]", dbconn)
            myCommand.Parameters.Add("CandidateNumber", OleDbType.Integer).Value = CanComboBox.Text
            Using myReader As OleDbDataReader = myCommand.ExecuteReader
                If (myReader.Read() = True) Then
                    NameTextBox.Text = (myReader("CandidateFname"))
                End If
            End Using
        End Using



        Try
            Dim cmd As New OleDb.OleDbCommand("Select COUNT(*) FROM Student_Voting GROUP BY CandidateNumber", dbconn)
            Dim dr As OleDbDataReader
            dr = cmd.ExecuteReader()
            Dim sum As Integer
            While (dr.Read())
                sum += dr(1)
            End While
            dr.Close()


        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        myCommand.Dispose()
        myReader.Close()
    End Sub



    Private Sub NovTextBox_TextChanged(sender As Object, e As EventArgs) Handles NovTextBox.TextChanged


    End Sub
End Class





i'm sorry for any dumb mistakes i made..im new to the programming scene
and of course thank you so much beforehand..

Is This A Good Question/Topic? 0
  • +

Replies To: Voting System, counting the total votes for each registered candidates

#2 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,026
  • Joined: 05-December 13

Re: Voting System, counting the total votes for each registered candidates

Posted 14 December 2018 - 01:39 PM

What's your question and what is the problem with the code you have?
Was This Post Helpful? 0
  • +
  • -

#3 ajucarat   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-December 18

Re: Voting System, counting the total votes for each registered candidates

Posted 14 December 2018 - 07:48 PM

Having problem with the select * count, it's wrong i got an error.. But since i am not on my computer rn, i can't really specify the error im sorry.. So i wanted to do the select * count to count the voters for each previously signed up candidate and display the total votes in number of voting(nov) textbox.. Thank you, i hope i explained it clearly..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1