Library Management System in C# with Source Code

The Library Management System is developed using C# language, this school library system project is a simple automated project aimed at simplifying the manner in which a book is published, saving time and effort.

You may properly keep track of books published, reissued and those not returned with the use of this method.

This removes the need to recruit many staff because the librarian can accomplish the regular transactions by himself at a given time with the aid of this device.

This school library management system in C# windows application is a simple system to use that will increase the library’s performance.

The library management system project in c sharp free download is designed to organize information automatically as its input into the system.

About Project Details

ABOUT PROJECTPROJECT DETAILS
Project Name :Library Management System
Project Platform :C#
Programming Language Used:C# Programming Language
Developer Name :itsourcecode.com
IDE Tool (Recommended):Visual Studio 2015
Project Type :Desktop Application
Database:MYSQL DATABASE

These are the following features of the system

  • Manages Books
  • Manage Borrowers
  • Manage Transactions
  • Manages Book Categories
  • Manages User
  • Inventory Reports
  • User Logs
  • Login and Logout

To run this project make sure that you have Visual Studio IDE and XAMPP installed in your PC(for Windows) to run this project. Library Management System in C#.net free download with source code.

Library Management System in C#: Steps On How To Run The Project

Time needed: 5 minutes

These are the steps on how to run library management system project C#

  • Step 1: Download

    First, download the source code given below.
    School-Library-Management-System-in-C#-Step-1

  • Step 2: Extract file

    Second, after you finished download the source code, extract the zip file.
    School-Library-Management-System-in-C#-Step-2

  • Step 3: Open Xampp

    Third, open xampp and start the Apache and MySQL.
    School-Library-Management-System-in-C#-Step-3

  • Step 4: Open browser

    Fourth, Open a browser and go to URL “http://localhost/phpmyadmin/”.
    School-Library-Management-System-in-C#-Step-4

  • Step 5: Create database

    Fifth, click on databases tab and Create database naming “dblibrary”.
    School-Library-Management-System-in-C#-Step-5

  • Step 6: Import

    Sixth, Click on browse file and select “dblibrary.sql” file which is inside the “SchoolLibrarySystem” folder and then click “Go“.
    School-Library-Management-System-in-C#-Step-6

  • Step 7: Open Visual Studio

    Seventh, Open a Visual Studio and open the folder SchoolLibrarySystem then click theLibrarySystem.sln“.
    School-Library-Management-System-in-C#-Step-7

  • Step 8: Start Project

    Eighth, Start the project.
    School-Library-Management-System-in-C#-Step-8

The Code Given Below Is For The Books Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LibrarySystem.Includes;
using LibrarySystem.Properties;

namespace LibrarySystem
{
    public partial class frmBooks : Form
    {
        public frmBooks()
        {
            InitializeComponent();
        }

        SQLConfig config = new SQLConfig();
        usableFunction funct = new usableFunction();
        string sql;

        private void btnNew_Click(object sender, EventArgs e)
        {

            funct.clearTxt(this);
            sql = "SELECT `AccessionNo`, `BookTitle`, `BookDesc` as 'Description', `Author`, `PublishDate`, `BookPublisher`, `Category`, BookType as 'TypeOfBooks', `BookPrice` as 'Price',DeweyDecimal,Remark,Status FROM `tblbooks` b, `tblcategory` c WHERE b.`CategoryId`=c.`CategoryId` ";
            config.Load_ResultList(sql, dtgList);

            sql = "SELECT CategoryId,Category From tblcategory WHERE Category !='ALL'  ORDER BY CATEGORY ASC";
            config.fiil_CBO(sql, cboCategory); 

            btnUpdate.Enabled = false;

            btnSave.Enabled = true;

            btnDelete.Enabled = false;
        }

        private void frmBooks_Load(object sender, EventArgs e)
        {
            btnNew_Click(sender, e);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {


            string datePublish = dtpDatePublish.Text;
            string remarks = "Donate";

            if (txtAccessionNo.Text == "" ||
                 txtAuthor.Text == "" || txtTitle.Text == ""
                 || txtDesc.Text == "" || txtPublisher.Text == "" )
            {
                MessageBox.Show("All fields are required to be filled up.", "Inavalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return; 
            }
              

            sql = "SELECT * FROM `tblbooks` WHERE `AccessionNo` = '" + txtAccessionNo.Text + "'";
            config.singleResult(sql);

            if (config.dt.Rows.Count > 0)
            {
                MessageBox.Show("Accession number is already in used.", "Inavalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            } 

            //        'adding books
            sql = "Insert Into `tblbooks` " +
                    " (`AccessionNo`, `BookTitle`, `BookDesc`, `Author`, `PublishDate`, `BookPublisher`, `CategoryId`, `BookPrice`, `BookQuantity`,Status,DeweyDecimal,OverAllQty,Remark,BookType) " +
                    " VALUES ('" + txtAccessionNo.Text + "','" + txtTitle.Text + "','" + txtDesc.Text + "','" + txtAuthor.Text + "','" + datePublish + "','" + txtPublisher.Text + "','" + cboCategory.SelectedValue + "','0',1, 'Available' ,'" + txtDeweyDecimal.Text + "',1,'" + remarks + "','" + cboType.Text + "')";

            config.Execute_CUD(sql, "failed to execute the query.", "Books has been saved in the database");


            sql = "SELECT * FROM `tblbooknumber` WHERE `BOOKTITLE` = '" + txtTitle.Text + "'";
            config.singleResult(sql);

            if (config.dt.Rows.Count > 0)
            {
                sql = "UPDATE `tblbooknumber` SET `QTY`=`QTY`+ 1 WHERE `BOOKTITLE`='" + txtTitle.Text + "'";
                config.Execute_Query(sql);
            }
            else
            {
                sql = "INSERT INTO  `tblbooknumber` (`BOOKTITLE`,`QTY`,`Desc`, `Author`, `PublishDate`, `Publisher`) " +
                      " VALUES ('" + txtTitle.Text + "',1,'" + txtDesc.Text + "','" + txtAuthor.Text + "','" + datePublish + "','" + txtPublisher.Text + "')";
                config.Execute_Query(sql);
            }

            frmBooks_Load(sender, e);
             

        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            string datePublish = dtpDatePublish.Text;
            string remarks = "Donate";

            if (txtAccessionNo.Text == "" ||
                 txtAuthor.Text == "" || txtTitle.Text == ""
                 || txtDesc.Text == "" || txtPublisher.Text == "")
            {
                MessageBox.Show("All fields are required to be filled up.", "Inavalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }


          
            sql = "Update `tblbooks` Set `BookTitle`='" + txtTitle.Text +
                    "', `BookDesc`='" + txtDesc.Text + "', `Author`='" + txtAuthor.Text + "', `PublishDate`='" + datePublish +
                    "', `BookPublisher`='" + txtPublisher.Text + "', `CategoryId`='" + cboCategory.SelectedValue + "', `DeweyDecimal`='" + txtDeweyDecimal.Text + 
                    "',Remark='" + remarks + "',BookType='" + cboType.Text + "'  WHERE `AccessionNo`='" + txtAccessionNo.Text + "'";
            config.Execute_CUD(sql, "failed to execute the query.", "Books has been updated in the database");
             
            frmBooks_Load(sender, e);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            sql = "DELETE FROM `tblbooks` WHERE `AccessionNo` = '" + txtAccessionNo.Text + "'"; 
            config.Execute_CUD(sql, "failed to execute the query.", "Books has been deleted in the database"); 

            sql = "DELETE FROM  `tblbooknumber` WHERE `BOOKTITLE`='" + txtTitle.Text + "'";
            config.Execute_Query(sql);

            frmBooks_Load(sender, e);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dtgList_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            txtAccessionNo.Text = dtgList.CurrentRow.Cells[0].Value.ToString();
        }

        private void txtAccessionNo_TextChanged(object sender, EventArgs e)
        {
            try
            {
                sql = "SELECT `AccessionNo`, `BookTitle`, `BookDesc` , `Author`, `PublishDate`, `BookPublisher`, `Category`, BookType ,DeweyDecimal,Remark  FROM `tblbooks` b, `tblcategory` c WHERE b.`CategoryId`=c.`CategoryId` AND  `AccessionNo`= '" + txtAccessionNo.Text + "'";
                config.singleResult(sql);
                if (config.dt.Rows.Count > 0)
                {
                    txtTitle.Text = config.dt.Rows[0].Field<string>(1);
                    txtDesc.Text = config.dt.Rows[0].Field<string>(2);
                    txtAuthor.Text = config.dt.Rows[0].Field<string>(3);
                    dtpDatePublish.Text = config.dt.Rows[0].Field<DateTime>(4).ToString();
                    txtPublisher.Text = config.dt.Rows[0].Field<string>(5);
                    cboCategory.Text = config.dt.Rows[0].Field<string>(6);
                    cboType.Text = config.dt.Rows[0].Field<string>(7);
                    txtDeweyDecimal.Text = config.dt.Rows[0].Field<string>(8);

                    btnUpdate.Enabled = true;
                    btnSave.Enabled = false;
                    btnDelete.Enabled = true;
                }
                else
                {
                    txtTitle.Clear();
                    txtDesc.Clear();
                    txtAuthor.Clear();
                    txtPublisher.Clear();
                    cboType.Text = "Unknown";

                    sql = "Select CategoryId,Category FROM tblcategory";
                    config.fiil_CBO(sql, cboCategory);


                    dtpDatePublish.Text = DateTime.Now.ToString("yyyy-MM-dd");
                    btnUpdate.Enabled = false;
                    btnSave.Enabled = true;
                    btnDelete.Enabled = false;
                }


            }
            catch (Exception ex)
            {
                this.Text = ex.Message;
            }
        }

        private void cboCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            //sql = "SELECT * FROM `tblcategory` WHERE  `CategoryId`=" + cboCategory.SelectedValue;
            //config.singleResult(sql);
            //txtDeweyDecimal.Text = config.dt.Rows[0].Field<string>(2); 
        }

        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            sql = "SELECT `AccessionNo`, `BookTitle`, `BookDesc` as 'Description', `Author`, `PublishDate`, `BookPublisher`, `Category`, BookType as 'TypeOfBooks', `BookPrice` as 'Price', DeweyDecimal,Remark,Status FROM `tblbooks` b, `tblcategory` c WHERE b.`CategoryId`=c.`CategoryId` AND (`BookTitle` Like '%" + txtSearch.Text + "%' OR `Author` Like '%" + txtSearch.Text + "%' OR `AccessionNo`  Like '%" + txtSearch.Text + "%')";
            config.Load_ResultList(sql, dtgList);
        }
    }
}

In this module which is the barrower is overdue.

Downloadable Source Code

Conclusion

This Library management System C# is only a project made for school requirement purposes only.

You can download this source code and modify it to suit your client requirements, since this is a student project it means you cannot really expect 100% functionality from this.

Inquiries

If you have any questions or suggestions about Library Management System project in C# with Source Code, please feel free to leave a comment below.

Frequently Asked Questions

How does this C# school management system work?

Modules: student enrollment, teacher/staff management, class scheduling, attendance, grade entry, report card generation, fee collection, library. Role-based access via login form. Built with C# WinForms + SQL Server. Foundation BSIT capstone.

What .NET and SQL Server versions does this project require?

Most projects in this batch use C# WinForms on .NET Framework 4.5+ (the dominant stack for tutorial sites) with SQL Server 2012 Express or higher. A few newer projects use .NET 6/7/8. To run: install Visual Studio 2019 / 2022 (Community edition is free), install SQL Server Express + SSMS, open the .sln file, build, run.

How do I set up the database for this C# project?

Open SQL Server Management Studio (SSMS) and connect to your SQL Server instance (e.g. localhost\SQLEXPRESS). Right-click Databases > Restore Database OR > New Database then import the included .sql script. Update the connection string in App.config (or in code-behind) with your server name + credentials. Rebuild and run.

Can I use this C# project for a BSIT capstone or thesis?

Yes, but extend it. A bare CRUD form is too narrow for full capstone scope. Add: role-based access (admin/staff/customer login redirect), Crystal Reports or RDLC reports, dashboard with Chart controls, audit log, multi-branch support. Pair with Chapter 1-5 documentation matching your panel’s rubric.

Why am I getting ‘connection error’ or ‘object reference not set’?

Three common C# issues: (1) Connection error: SQL Server isn’t running OR connection string in App.config has wrong server name. Open SQL Server Configuration Manager + verify SQL Server (SQLEXPRESS) service is running. (2) NullReferenceException: a control reference or DB column returned NULL, add a check or use ?? operator. (3) Build error ‘The type or namespace could not be found’: missing assembly reference, add via Project > Add Reference.

Where can I find more C# projects with source code?

Browse the C# Projects hub for the full library. For other .NET stacks see VB.NET Projects (300+ Windows Forms systems). For ASP.NET WebForms see ASP.NET Projects. For BSIT capstone idea lists see 150 Best Capstone Project Ideas.

Adrian Mercurio

Full-Stack Developer at PIES IT Solution

Specializes in building complete capstone projects with full documentation. Strong background in PHP/MySQL development and database design. Has personally built and tested over 30 capstone-ready projects with ER diagrams, DFDs, and chapter-by-chapter thesis documentation.

Expertise: PHP · Laravel · Database Design · Capstone Projects · C# · C · C++ · Python · AI Projects  · View all posts by Adrian Mercurio →

4 thoughts on “Library Management System in C# with Source Code”

  1. After I run source code I cannot enter enter into Login page and it says that Account doesn’t exist. Please contact administrator. so what must I do to enter into this system?

Leave a Comment