Let’s Make Software Engineering Simple
Esoft Wennappuwa & Chilaw
C# Sample Project
Student Management System
Forms
1. Loading
2. Login
3. Home
4. Student Registration
5. Student Update/Delete
6. View Student Details
Here We Go…….
1. Loading Design
Label
Progress bar
Loading Code
public partial class Loading : Form
{
Timer timer; Type this code
public Loading()
{
InitializeComponent();
InitializeTimer(); Type this code
}
private void InitializeTimer()
{
timer = new Timer(); Type this code
[Link] = 100;
[Link] += new EventHandler(timer_Tick);
[Link]();
}
private void Loading_Load(object sender, EventArgs e)
{
[Link] = 0;
[Link] = 100; Type this code
[Link] = 0;
}
private void timer_Tick(object sender, EventArgs e)
{
if ([Link] < [Link])
{
[Link] += 2;
}
else
{
[Link](); Type this code
[Link]();
Login loginform = new Login();
[Link]();
}
}
2. Login Page Design
Label
Label Picture box
Textbox
Label
Textbox
Button Button
Login Page Code
Double click this button Double click this button
and type the code and type the code
Code Code
Login Button Code
private void btnlogin_Click(object sender, EventArgs e)
{
string username = [Link];
string password = [Link];
if (username == "Harishan" && password == "@123")
{
[Link]("Login Success");
[Link]();
home obj = new home();
[Link](); Type this code
}
else
{
[Link]("Invalid Username/Password");
}
Exit Button Code
private void btnexit_Click(object sender, EventArgs e)
{
[Link](); Type this code
3. Home
Label
Button
Picture Box
Button
Picture Box
Button
Picture Box
Button
Home Code
Double click this button
and type the code
Code
Double click this button
and type the code
Code
Double click this button
and type the code Double click this button
and type the code
Code
Code
Move to Student Registration Form Code
private void btnstdregform_Click(object sender, EventArgs e)
{
Student obj = new Student();
[Link](); Type this code here
[Link]();
}
Move to Update/Delete Student Details Form Code
private void btnupdatedelete_Click(object sender, EventArgs e)
{
UPDATESTUDENT obj = new UPDATESTUDENT();
[Link](); Type this code here
[Link]();
Move to View Student Details Form Code
private void btnviewstudent_Click(object sender, EventArgs e)
{
Viewstudent obj = new Viewstudent();
[Link](); Type this code here
[Link]();
Back Button Code
private void btnback_Click(object sender, EventArgs e)
{
Login obj = new Login();
[Link](); Type this code here
[Link]();
}
4. Student Registration Form
Label
Picture Box
Label Textbox
Label Textbox
Label DateTimePicker
Label ComboBox
Label Textbox
Label Textbox
Label Textbox
Button Button Button
Student Registration Form Code
Double click this button Double click this button
and type the code and type the code
Code Code
Database Connection Code of Student Registration.
Type this code here
You must add your connection string here, to know
how to get your connection string - click here
using [Link];
private string connectionString = @" ";
Register Button Code
Type this code here
private void btnregister_Click(object sender, EventArgs e)
string firstName = [Link];
string lastName = [Link];
DateTime dateOfBirth = [Link];
string gender = [Link]();
int phoneNumber = [Link]([Link]);
string address = [Link];
string studentId = [Link];
// SQL query to insert data
string query = "INSERT INTO STUDENT (FIRSTNAME, LASTNAME, DATEOFBIRTH,
GENDER, PHONENUMBER, ADDRESS, STUDENTID) " +
"VALUES (@FirstName, @LastName, @DateOfBirth, @Gender,
@PhoneNumber, @Address, @StudentId)";
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
[Link]();
using (SqlCommand command = new SqlCommand(query, connection))
{
// Add parameters to avoid SQL injection
[Link]("@FirstName", firstName);
[Link]("@LastName", lastName);
[Link]("@DateOfBirth", dateOfBirth);
[Link]("@Gender", gender);
[Link]("@PhoneNumber", phoneNumber);
[Link]("@Address", address);
[Link]("@StudentId", studentId);
// Execute the query
[Link]();
[Link]("Data saved successfully!");
}
}
catch (SqlException ex)
{
[Link]("Error"+ex);
}
}
}
Reset Button Code
private void btnreset_Click(object sender, EventArgs e)
{ Type this code here
[Link] = "";
[Link] = "";
[Link] = "";
[Link] = "";
[Link] = "";
[Link] = "";
[Link] = "";
5. Student Update / Delete Form
Just Copy & Paste The Same Design Of Student Registration Form To The Update / Delete
Form. Because We Need The Same Design Recheck The Values When Updating And
Deleting. You Just Have To Change The Names Of The Buttons According To It’s Function.
Student Update / Delete Form Code
Double click this button Double click this button Double click this textbox
and type the code and type the code and type the code
Code Code Code
Database Connection Code of Student Update / Delete Form
Type this code here
Type this code here
Type this code here
Update Button Code
Type this code
private void btnupdate_Click(object sender, EventArgs e)
string firstName = [Link];
string lastName = [Link];
DateTime dateOfBirth = [Link];
string gender = [Link]();
int phoneNumber = [Link]([Link]);
string address = [Link];
string studentId = [Link];
string query = "UPDATE STUDENT SET FIRSTNAME = @FirstName, LASTNAME = @LastName, DATEOFBIRTH = @DateOfBirth, " + "GENDER
= @Gender, PHONENUMBER = @PhoneNumber, ADDRESS = @Address WHERE STUDENTID = @StudentId";
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
[Link]();
using (SqlCommand command = new SqlCommand(query, connection))
{
// Add parameters to avoid SQL injection
[Link]("@FirstName", firstName);
[Link]("@LastName", lastName);
[Link]("@DateOfBirth", dateOfBirth);
[Link]("@Gender", gender);
[Link]("@PhoneNumber", phoneNumber);
[Link]("@Address", address);
[Link]("@StudentId", studentId);
// Execute the query
int rowsAffected = [Link]();
if (rowsAffected > 0)
{
[Link]("Data updated successfully!");
}
else
{
[Link]("Student ID not found.");
}
}
}
catch (SqlException ex)
{
[Link]("Error: " + [Link]);
}
}
}
Delete Button Code
Type this code
private void btndelete_Click(object sender, EventArgs e)
string studentId = [Link];
if ([Link](studentId))
{
[Link]("Please enter a valid Student ID.");
return;
}
DialogResult result = [Link]("Are you sure you want to delete this student?", "Confirm Deletion",
[Link], [Link]);
if (result == [Link])
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
[Link]();
string query = "DELETE FROM STUDENT WHERE STUDENTID = @StudentId";
using (SqlCommand command = new SqlCommand(query, connection))
{
[Link]("@StudentId", studentId);
int rowsAffected = [Link]();
if (rowsAffected > 0)
{
[Link]("Student deleted successfully.");
}
else
{
[Link]("Student ID not found.");
}
}
}
catch (SqlException ex)
{
[Link]("Error: " + [Link]);
}
}
}
}
StudentID TextBox Code
Type this code
private void studentIdTextBox_TextChanged(object sender, EventArgs e)
string studentId = [Link];
if ()
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
[Link]();
string query = "SELECT FIRSTNAME, LASTNAME, DATEOFBIRTH, GENDER, PHONENUMBER, ADDRESS FROM STUDENT WHERE STUDENTID = @StudentId";
using (SqlCommand command = new SqlCommand(query, connection))
{
[Link]("@StudentId", studentId);
using (SqlDataReader reader = [Link]())
{
if ([Link]())
{
[Link] = reader["FIRSTNAME"].ToString();
[Link] = reader["LASTNAME"].ToString();
[Link] = [Link](reader["DATEOFBIRTH"]);
[Link] = reader["GENDER"].ToString();
[Link] = reader["PHONENUMBER"].ToString();
[Link] = reader["ADDRESS"].ToString();
}
else
{
}
}
}
}
catch (SqlException ex)
{
[Link]("Error: " + [Link]);
}
}
}
}
6. View Student Form
Label Label
PictureBox
TextBox
DataGridView
Button
View Student Form Code
Double click on the form
and type the code
Code
Double click this textbox
and type the code
Code
View Student Form Database Connection Code
Type this code here
Type this code here
Type this code here
StudentID TextBox Code
Type this code
private void studentIdTextBox_TextChanged(object sender, EventArgs e)
{
string studentId = [Link];
if ()
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
[Link]();
string query = "SELECT * FROM STUDENT WHERE STUDENTID = @StudentId";
using (SqlCommand command = new SqlCommand(query, connection))
{
[Link]("@StudentId", studentId);
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
DataTable dataTable = new DataTable();
[Link](dataTable);
[Link] = dataTable;
}
}
catch (SqlException ex)
{
[Link]("Error: " + [Link]);
}
}
}
else
{
// Optionally clear the DataGridView if the text box is empty
[Link] = null;
}
}
Type this code in the view student form
private void LoadAllStudents()
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
[Link]();
string query = "SELECT * FROM STUDENT";
using (SqlCommand command = new SqlCommand(query, connection))
{
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
DataTable dataTable = new DataTable();
[Link](dataTable);
[Link] = dataTable;
}
}
catch (SqlException ex)
{
[Link]("Error: " + [Link]);
}
}
Type this code
Double click the view student form and type this code
private void Viewstudent_Load(object sender, EventArgs e)
{
LoadAllStudents(); Type this code
}
Now Let’s Create the
Database
STEP 1: Go to “PROJECT”
STEP 2:
Click “Add New Data Source”
STEP 3: Select “Database”
Then click “Next”
STEP 4:
Now click “Dataset”
Then click “Next”
STEP 5:
Now click “New Connection”
STEP 6: Click “Change”
STEP 7:
Select “Microsoft SQL Server Database File”
Then Click “OK”
STEP 8: Type Your Database Name Here
Then click “OK”
STEP 9:
Then click “Next”
STEP 10:
Then click “Next”
STEP 11:
Then click “Finish”
STEP 12:
Now Under Database Explorer You Can See the Database That You’ve Created
Double Click Your
Database
STEP 13:
Then click “Add New Table”
Now Double Click
the Folder “Tables”
STEP 14:
Click Update After Creating the Table
Set Primary Key If
needed
Type Your Table Name within
the square brackets [ ]
For example : STUDENT
Now let’s see how to get the connection string
1.
Right click the
Database
Then click properties
2.
Double click this and
copy the connection
string of your database
3.
Paste the connection string here
private string connectionString = @" ";
This documentation is designed with the intention of simplifying software
engineering concepts for beginners. I hope this guide helps students in their
journey to understand and implement a practical project. Feel free to use,
adapt, and expand this project for your learning.
Thank you,
Chandrasekaran Harishan