Voter's ID Finder for Supreme Student Government using Visual basic.Net

This time, I'm going to show you how to create a "Voter's ID finder" for Supreme Student Government. The system also has a load of all data from the database and you can also search for specific student by using the quick search and display the result to the datagrid. To start building this project, you need to add two textbox, three buttons, three label and a datagridview and last a timer. Then name the button1 as “btnload” and the Text property to “Load Data”, next the button2 name it as “bntsearch” and chande the Text property to “Search” and last the button3 name is as “btnexit” and chage the Text property to “Exit”. And retain all properties for the rest of objects available. Then the final output of this program after designing should look like as shown This time, we need to add functionality to our program. To do this double click our main form, then under public class add the following code: The new added code is a function, and this function will hold our two technology name as “Provider” and “Data Source” and will always return a new Connection. And our database name is “votedb” and it is stored in the “bin” folder.
  1. Private Function GetConnection() As OleDb.OleDbConnection
  2.         Return New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & Application.StartupPath & "\votedb.accdb")
  3.     End Function
Next, inside the form load, add the following code:
  1.     'will hide the Type: Lastname or Course and textbox and start the timer for time
  2.         Label1.Hide()
  3.         TextBox1.Hide()
  4.         Timer1.Start()
Then we will add functionality to our “btnload” button, to do this double click this button and add the following code.
  1. Private Sub btnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnload.Click
  2.         'declare dt as new datatable, this will hold later the value from data adapter
  3.         Dim dt As New DataTable
  4.         'declare conn as connection and it will now a new connection because it is equal to Getconnection Function
  5.         Dim conn As OleDb.OleDbConnection = GetConnection()
  6.         Try
  7.             'this is our query to display all the values from the table
  8.             Dim sql As String = "SELECT Name, Course_yr, voteid, Laboratory FROM votersid"
  9.             'bind sql statement and connection and pass the result to da
  10.             Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, conn)
  11.             'it fills the value from da to datatable named dt
  12.             da.Fill(dt)
  13.             'fill the datagridview by getting fron dt
  14.             DataGridView1.DataSource = dt
  15.  
  16.  
  17.         Finally
  18.             'close connection
  19.             conn.Close()
  20.         End Try
  21.  
  22.     End Sub
Next, to double click “btnsearch”, and the following code: It displays the Type: Lastname or Course and textbox and so that it can allow user input for searching specific student.
  1.         Label1.Show()
  2.         TextBox1.Show()
  3.         With TextBox1.Text
  4.             Focus()
  5.         End With
This time, we will add functionality for our quick search option. To do this, add the following code:
  1.    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  2.         Dim dt As New DataTable
  3.         Dim conn As OleDb.OleDbConnection = GetConnection()
  4.         Try
  5.  
  6.             Dim sql As String = "SELECT Name, Course_yr, voteid, Laboratory FROM votersid where  Name Like '%" & TextBox1.Text & "%'or Course_yr like'%" & TextBox1.Text & "%'"
  7.             Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, conn)
  8.             da.Fill(dt)
  9.             DataGridView1.DataSource = dt
  10.  
  11.  
  12.         Finally
  13.             conn.Close()
  14.             conn.Dispose()
  15.         End Try
  16.     End Sub
To display the time, double click the “timer” and add the following code:
  1. 'it gets the current time and this is based on local machine
  2.         TextBox2.Text = TimeOfDay
And finally double click the “btnexit” button, and add the following code: This simply terminate the application.
  1. Me.Close()
This time, you can now test your program by pressing “F5”.

Add new comment