Student Result Project in VB.NET is a complete mini project with one form and a data report . The Student Result project has only one form that allows the user to enter basic student details and her marks. It then generates the report card for the student that can be viewed on screen exported to a file or printed.
The tables used are the following
Working of Student Result Project in VB.NET
The form is created with text boxes for Student ID, Name, Father Name, Mother’s Name, Phone and email. Gender is selected from radio buttons. Course/ Class is selected from a combobox that gets the list of courses from “Degree “ Column of “SubMaster” Table.
When a course is selected the grid fills with the subject names from “Subject” column of “SubMaster” corresponding to the course value in combobox. User can fill the marks in the available subjects in the datagrid.
This the module code for project.
Public conDB As New OleDb.OleDbConnection Public Sub connectDB() If conDB.State = ConnectionState.Closed Then conDB.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\stuDB.accdb" conDB.Open() End If End Sub Function getNewID(tblName As String, fldName As String) As String Dim strVal, sql As String Dim cmd As OleDb.OleDbCommand connectDB() sql = "select max(" & fldName & ") from " & tblName cmd = New OleDb.OleDbCommand(sql, conDB) strVal = Convert.ToString(cmd.ExecuteScalar()) If strVal = "" Then strVal = "1" Else strVal = Convert.ToString(CInt(strVal) + 1) End If Return strVal End Function
Save Button
On clicking the save button student details in textboxes, radio buttons and combo box are stored in the “StudentMaster” Table. For same studentID the subjects and marks from the datagrid are stored in the “StudentMarks” Table.
Button -btnSave Click event
Dim strSQL As String Dim gndr As String Dim i As Integer If rdbFemale.Checked = True Then gndr = "Female" Else gndr = "Male" End If strSQL = "insert into studentmaster values(" & txtStuID.Text & ",'" & cboClass.Text & "','" & txtStuName.Text & "','" & txtFName.Text & "','" & txtMName.Text & "','" & gndr & "','" & txtPhone.Text & "','" & txtEmail.Text & "')" cmd = New OleDb.OleDbCommand(strSQL, conDB) cmd.ExecuteNonQuery() For i = 0 To dgvMarks.RowCount - 2 strSQL = "insert into studentmarks values(" & txtStuID.Text & ",'" & dgvMarks.Item(0, i).Value & "'," & dgvMarks.Item(1, i).Value & ")" cmd = New OleDb.OleDbCommand(strSQL, conDB) cmd.ExecuteNonQuery() Next
Search, Update and Delete Buttons
When the search button is clicked an inputbox appears on screen prompting to enter a student ID. On entering Student ID of an existing students its data is displayed in the from controls.
This can be modified and updated by pressing the “Update” Button. The search record can be deleted by clicking the “Delete” button.
Button btnSearch Click event
Dim sid, cnt As Integer Dim drl As OleDb.OleDbDataReader Dim cmdl As New OleDb.OleDbCommand sid = CInt(InputBox("Enter the StudentID to search")) cmdl = New OleDb.OleDbCommand("select * from studentmaster where stuid=" & sid, conDB) drl = cmdl.ExecuteReader() If drl.Read() Then txtStuID.Text = drl.Item(0) cboClass.Text = drl.Item(1) txtStuName.Text = drl.Item(2) txtFName.Text = drl.Item(3) txtMName.Text = drl.Item(4) If drl.Item(5) = "Female" Then rdbFemale.Checked = True Else rdbMale.Checked = True End If txtPhone.Text = drl.Item(6) txtEmail.Text = drl.Item(7) drl.Close() cmdl = New OleDb.OleDbCommand("select subject, marks from studentmarks where stuid=" & sid, conDB) drl = cmdl.ExecuteReader() dgvMarks.Rows.Clear() cnt = 0 While drl.Read() dgvMarks.Rows.Add() dgvMarks.Item(0, cnt).Value = Convert.ToString(drl.Item(0)) dgvMarks.Item(1, cnt).Value = Convert.ToString(drl.Item(1)) cnt = cnt + 1 End While Else MsgBox("No student with this ID") End If
Button btnUpdate Click event
Dim strSQL As String Dim gndr As String Dim i As Integer If rdbFemale.Checked = True Then gndr = "Female" Else gndr = "Male" End If strSQL = "update studentmaster set stuClass='" & cboClass.Text & "', StuName='" & txtStuName.Text & "', StuFname='" _ & txtFName.Text & "',StuMName='" & txtMName.Text & "',StuGender='" & gndr & "',StuPhone='" & txtPhone.Text _ & "',StuEmail='" & txtEmail.Text & "' where StuID=" & CInt(txtStuID.Text) cmd = New OleDb.OleDbCommand(strSQL, conDB) cmd.ExecuteNonQuery() ' delete all records from marks table to add the new marks and subjects strSQL = "delete * from studentmarks where StuID=" & CInt(txtStuID.Text) cmd = New OleDb.OleDbCommand(strSQL, conDB) cmd.ExecuteNonQuery() ' Insert the new subjects and marks for the student For i = 0 To dgvMarks.RowCount - 2 strSQL = "insert into studentmarks values(" & txtStuID.Text & ",'" & dgvMarks.Item(0, i).Value & "'," & dgvMarks.Item(1, i).Value & ")" cmd = New OleDb.OleDbCommand(strSQL, conDB) cmd.ExecuteNonQuery() Next
Button btnDelete Click event
Dim strSQL As String ' delete the record of student from master table strSQL = "delete * from studentmaster where StuID=" & CInt(txtStuID.Text) cmd = New OleDb.OleDbCommand(strSQL, conDB) cmd.ExecuteNonQuery() ' delete all records from marks table strSQL = "delete * from studentmarks where StuID=" & CInt(txtStuID.Text) cmd = New OleDb.OleDbCommand(strSQL, conDB) cmd.ExecuteNonQuery()
Print Button
When a record is searched by passing on the student ID, her report card can be printed by clicking the “Print” button. A data report appears on screen showing student details and her marks in each subject. The report also displays the total marks of the five subjects.
Button btnPrint Click event
Dim frm As New Form2 ' creates an object of form containing the reportviewer frm.Show()' displays the report
code for the form containing ReportViewer (Form2 Load Event)
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim dt1, dt2 As New DataTable Dim sid As Integer connectDB() sid = CInt(frmStuDetails.Controls("txtStuID").Text) Dim cmd1 As New OleDb.OleDbCommand("SELECT * from StudentMarks where stuid=" & sid, conDB) cmd1.CommandTimeout = 4096 Dim ta1 As New OleDb.OleDbDataAdapter(cmd1) ta1.Fill(dt1) Dim cmd2 As New OleDb.OleDbCommand("SELECT * from StudentMaster where stuid=" & sid, conDB) cmd2.CommandTimeout = 4096 Dim ta2 As New OleDb.OleDbDataAdapter(cmd2) ta2.Fill(dt2) With Me.ReportViewer1.LocalReport .DataSources.Clear() .DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dt1)) .DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet2", dt2)) End With Me.ReportViewer1.RefreshReport() End Sub
To print the report two data tables are used. One stores the student personal details(Dataset1) and the other stores the marks details( Dataset2).
This is the design of the report.
This the report after launching. The data report has a print button to get a hard copy with attached printer. It can also be exported to an Excel, PDF or Word File for later printing or sharing.
Final words
This is a mini project that explains how a form is created that can save data into two different tables. You have also learned to make a master-detail report using data from two tables. You can download and update the project according to your need. Validation checks can be added to this project.