Student Registration System in C#

Student Registration System C# is one of the most important projects for beginners in order to learn basic database operations of C#. It can be used as a module or a sub module in any school management system for any learning institute.

In this very quick tutorial, We’ll learn how to develop a very simple student management system in C#. We’ll use WinForms Applications of Microsoft C# .NET.

Tools Required:

  1. Microsoft Visual Studio 2010 or later version recommended.
  2. SLR Db Connector DLL File. Please Download it from THIS LINK.
  3. Microsoft SQL Server 2008 or later version recommended.

Steps to Follow:

  1. Open your Visual Studio and create a new windows forms application project.
  2. Name the project as StudentRegistrationSystem and hit enter.
  3. I assume you followed all steps to configure SLR Db Connector after importing the DLL File of it. Please follow THIS LINK to learn the basics of SLR Db Connector Library.
  4. Now select your form and change the BorderStyle property to none.
  5. Change AutoScaleMode property to none.
  6. For this specific tutorial, I’ve used the Form size property to 1031, 557.
  7. Lets add the form components from the Tool Box. First of all add a panel control and set the dock property to top and add a background color of RGB 8, 47, 78.
  8. Add a label control and change the fonts as per requirement.
  9. Now change the foreground color of labels to white so that the text on the panels will be easily visible.
  10. Add some more labels and text boxes for Name, Father Name, Address, Date of birth and Class properties.
  11. We will use text boxes for Name, father name and address, Date Time Picker for Date of Birth and Combo box for class. see the image below for a clear understanding.
Form of Student Registration System

Creating the Database:

Now its time to create a simple database for our student registration system.

  1. Open your SQL Server Management Studio and Go to the Object Explorer -> Right Click on Databases -> New Database and name this database as srsdb (short form for Student Registration System Database) and click on OK button.
  2. Now create two tables, one for students and other for classes.
  3. The attributes for class table is Classes are just id and name as mentioned in image below:
Create Class Table

4. Attributes for Students table are id, name, father name, address, date of birth and class id. class id will be foreign key in students table.

Create Students table

5. Now open your visual studio, go to the onLoad event of your form and add the following code to fill the class combo box with all classes available in database,

        DbConnector db;
        public Form1()
        {
            InitializeComponent();
            db = new DbConnector();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            db.FillCombobox("select name from tblClasses", cmbClass);
            db.fillDataGridView("select * from tblStudents", dataGridView1);
        }

6. To insert student records, first of all we will add some validations to our form so that we the user will not be able to insert null values. For that, we will create a method like,

        private bool isFormValid()
        {
            if (txtName.Text.ToString().Trim() == string.Empty 
                || txtFatherName.Text.ToString().Trim() == string.Empty 
                || txtAddress.Text.ToString().Trim() == string.Empty)
            {
                return false;
            }

            return true;
        }

7. After this validation, we are ready to insert values from our form.

string class_id;

 if (isFormValid())
  {
//Selecting id from database
                db.getSingleValue("select id from tblClasses where name = '" + cmbClass.SelectedText.ToString() + "'", out class_id, 0);

//inserting values.
                db.performCRUD("insert into tblStudents(name,father_name,address,date_of_birth,class_id) values('"+txtName.Text+ "','" + txtFatherName.Text + "','" + txtAddress.Text + "','" + dtdob.Text + "','" + class_id + "')");

this.OnLoad(e);
            }
            else
            {
                MessageBox.Show("Please Fill All Required Fields","Required Fields are Empty",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }

Source Code: