27 tháng 5, 2014

Chương trình Quản lý sinh viên bằng C# (CSharp)


Bạn đang tìm chương trình Quản lý sinh viên bằng C# (CSharp)? Có thể, VN Wallet là nơi hữu ích để bạn tham khảo và thực hiện công việc mà bạn đang cần. Chương trình Quản lý sinh viên bằng C# trong bài viết bao gồm: Form Sinh viên, Form Khoa, Form Môn học, Form Kết quả, Form Thêm sinh viên, Form Thêm khoa, Form Thêm môn học...

Dưới đây là nơi tham khảo dành cho bạn:

Trong form chính Quản lý sinh viên, bạn thực hiện như sau:


using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Chuongtrinhquanlysinhvien { public partial class Quanlysinhvien : Form { public Quanlysinhvien() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Application.Exit(); } private void buttonSinhvien_Click(object sender, EventArgs e) { Sinhvien _Sinhvien = new Sinhvien(); _Sinhvien.Show(); Hide(); } private void buttonKhoa_Click(object sender, EventArgs e) { Khoa _Khoa = new Khoa(); _Khoa.Show(); Hide(); } private void buttonMonhoc_Click(object sender, EventArgs e) { Monhoc _Monhoc = new Monhoc(); _Monhoc.Show(); Hide(); } private void buttonKetqua_Click(object sender, EventArgs e) { Ketqua _Ketqua = new Ketqua(); _Ketqua.Show(); Hide(); } } }

Trong form Sinh viên, bạn thực hiện như sau:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;//Khai bao ket noi du lieu sql
namespace Chuongtrinhquanlysinhvien
{
    public partial class Sinhvien : Form
    {
        private SqlConnection conn;//Khai bao bien ket noi
        private DataTable dt = new DataTable("TableSinhvien");//Gan dt la table can ket noi
        private DataTable dtkhoa = new DataTable("TableKhoa");
        private SqlDataAdapter da = new SqlDataAdapter(); //Gan da la csdl can ket noi
        private void connect()
        {
            String cn = "Data Source=JackyChan;Initial Catalog=QuanLySinhVien;Integrated Security=True";//chuoi ket noi
            try
            {
                conn = new SqlConnection(cn);//Gan chuoi ket noi
                conn.Open();//Mo ket noi
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể kết nối tới cơ sở dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void disconnect()
        {
            conn.Close();//Dong ket noi
            conn.Dispose();//Giai phong tai nguyen
            conn = null;//Huy doi tuong
        }
        public Sinhvien()
        {
            InitializeComponent();
        }

        private void buttonThoat_Click(object sender, EventArgs e)
        {
            Quanlysinhvien _Quanlysinhvien = new Quanlysinhvien();
            _Quanlysinhvien.Show();
            Hide();
        }

        private void Sinhvien_Load(object sender, EventArgs e)
        {
            connect();//Goi ham ket noi
            getdata ();//Goi ham getdata
            duadulieu();//Gio ham dua du lieu
            textBoxMasinhvien.Enabled = false;//An Ma sinh vien khong cho phep sua
        }
        private void getdata()
        {
            SqlCommand command = new SqlCommand();//Khai bao 1 command
            command.Connection = conn;//Ket noi
            command.CommandType = CommandType.Text;//Khai bao kieu command
            command.CommandText = @"Select 
                                           Masv as N'Masv',
                                           Holot as N'Holot',
                                           Ten as N'Ten',
                                           (Case phai when 1 then N'Nam' else N'Nữ' end)as N'Phai',
                                           Ngaysinh as N'Ngaysinh',
                                           Makhoa as N'Makhoa'
                                           from Sinhvien";//Viet cau truy van
            da.SelectCommand = command;//Gan command cho da
            da.Fill(dt);//Nap du lieu cho table
            dataGridViewSinhvien.DataSource = dt;//Load du lieu len datagridview
            //Combobox cho Makhoa
            command.CommandText = "Select * from Khoa";
            da.SelectCommand = command;
            da.Fill(dtkhoa);
            comboBoxMakhoa.DataSource = dtkhoa;
            comboBoxMakhoa.DisplayMember = "Makhoa";
            comboBoxMakhoa.ValueMember = "Makhoa";
            comboBoxMakhoa.SelectedValue = "Makhoa";
        }
        private void duadulieu()
        {
            textBoxMasinhvien.DataBindings.Clear();
            textBoxMasinhvien.DataBindings.Add("Text", dataGridViewSinhvien.DataSource, "Masv");
            textBoxHolot.DataBindings.Clear();
            textBoxHolot.DataBindings.Add("Text", dataGridViewSinhvien.DataSource, "Holot");
            textBoxTen.DataBindings.Clear();
            textBoxTen.DataBindings.Add("Text", dataGridViewSinhvien.DataSource, "Ten");
            comboBoxPhai.DataBindings.Clear();
            comboBoxPhai.DataBindings.Add("Text", dataGridViewSinhvien.DataSource, "Phai");
            dateTimePickerNgaysinh.DataBindings.Clear();
            dateTimePickerNgaysinh.DataBindings.Add("Text", dataGridViewSinhvien.DataSource, "Ngaysinh");
            comboBoxMakhoa.DataBindings.Clear();
            comboBoxMakhoa.DataBindings.Add("Text", dataGridViewSinhvien.DataSource, "Makhoa");
        }

        private void buttonXoa_Click(object sender, EventArgs e)
        {
            DataRow row = dt.Select("Masv = '" + textBoxMasinhvien.Text + "'")[0];
            row.BeginEdit();
            row.Delete();
            row.EndEdit();
            SqlCommand commanDelete = new SqlCommand();
            commanDelete.Connection = conn;
            commanDelete.CommandType = CommandType.Text;
            commanDelete.CommandText = "Delete from Sinhvien where Masv=@Masv";
            commanDelete.Parameters.Add("@Masv", SqlDbType.VarChar, 5, "Masv");
            da.DeleteCommand = commanDelete;
            da.Update(dt);
            MessageBox.Show("Bạn đã xóa thành công!", "THÔNG BÁO", MessageBoxButtons.OK);

        }

        private void buttonSua_Click(object sender, EventArgs e)
        {
            DataRow row = dt.Select("Masv = '" + textBoxMasinhvien.Text + "'")[0];
            row.BeginEdit();
            row["Holot"] = textBoxHolot.Text;
            row["Ten"] = textBoxTen.Text;
            row["Phai"] = comboBoxPhai.SelectedValue;
            row["Ngaysinh"] = dateTimePickerNgaysinh.Value;
            row["Makhoa"] = comboBoxMakhoa.SelectedValue;
            row.EndEdit();
            SqlCommand commandUpdate = new SqlCommand();
            commandUpdate.Connection = conn;
            commandUpdate.CommandType = CommandType.Text;
            commandUpdate.CommandText = @"Update Sinhvien set Masv=@Masv,Holot=@Holot,Ten=@Ten,Phai=@Phai,Ngaysinh=@Ngaysinh, Makhoa=@Makhoa Where Masv=@Masv";
            commandUpdate.Parameters.Add("@Masv", SqlDbType.VarChar, 5, "Masv");//An khong duoc sua
            commandUpdate.Parameters.Add("@Holot", SqlDbType.NVarChar, 30, "Holot");//Sua xong
            commandUpdate.Parameters.Add("@Ten", SqlDbType.NVarChar, 10, "Ten");//Sua xong
            commandUpdate.Parameters.Add("@Phai", SqlDbType.Bit, 2, "Phai");
            commandUpdate.Parameters.Add("@Ngaysinh", SqlDbType.DateTime, 10, "Ngaysinh");//Sua xong
            commandUpdate.Parameters.Add("@Makhoa", SqlDbType.VarChar, 5, "Makhoa");//Sua xong
            da.UpdateCommand = commandUpdate;
            da.Update(dt);
            MessageBox.Show("Bạn đã sửa thành công!", "THÔNG BÁO", MessageBoxButtons.OK);           
        }

        private void buttonThem_Click(object sender, EventArgs e)
        {
            ThemSinhvien _Themsinhvien = new ThemSinhvien();
            _Themsinhvien.Show();
            Hide();
        }  
    }
}

Trong form Thêm sinh viên, bạn thực hiện:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;//khai bao sql;
namespace Chuongtrinhquanlysinhvien
{
    public partial class ThemSinhvien : Form
    {
        private SqlConnection conn;//Khai bao bien ket noi
        private DataTable dt = new DataTable("TableSinhvien");//Gan dt la table can ket noi
        private DataTable dtkhoa = new DataTable("TableKhoa");
        private SqlDataAdapter da = new SqlDataAdapter(); //Gan da la csdl can ket noi
        private Boolean kt;//Khai bao
        private void connect()
        {
            String cn = "Data Source=JackyChan;Initial Catalog=QuanLySinhVien;Integrated Security=True";//chuoi ket noi
            try
            {
                conn = new SqlConnection(cn);//Gan chuoi ket noi
                conn.Open();//Mo ket noi
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể kết nối tới cơ sở dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void getdata()
        {
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandType = CommandType.Text;
            command.CommandText = "Select * from Sinhvien";
            da.SelectCommand = command;
            da.Fill(dt);
            //Combobox cho Makhoa
            command.CommandText = "Select * from Khoa";
            da.SelectCommand = command;
            da.Fill(dtkhoa);
            comboBoxMakhoa.DataSource = dtkhoa;
            comboBoxMakhoa.DisplayMember = "Makhoa";
            comboBoxMakhoa.ValueMember = "Makhoa";
            comboBoxMakhoa.SelectedValue = "Makhoa";

        }
        private void disconnect()
        {
            conn.Close();//Dong ket noi
            conn.Dispose();//Giai phong tai nguyen
            conn = null;//Huy doi tuong
        }
        public ThemSinhvien()
        {
            InitializeComponent();
        }

        private void buttonThoat_Click(object sender, EventArgs e)
        {
            Sinhvien _Sinhvien = new Sinhvien();
            _Sinhvien.Show();
            Hide();
        }
        private bool kiemtra()//Kiem tra Ma sinh vien
        {
            kt = true;
            if (textBoxMasinhvien.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập Mã sinh viên! Mã sinh viên không được trùng!", "THÔNG BÁO", MessageBoxButtons.OK);
                kt = false;
            }
            return kt;

        }
        private void buttonLuu_Click(object sender, EventArgs e)
        {
            kiemtra();
            if (kt == true)
            {
                DataRow row = dt.NewRow();
                row["Masv"] = textBoxMasinhvien.Text;
                row["Holot"] = textBoxHolot.Text;
                row["Ten"] = textBoxTen.Text;
                if (comboBoxPhai.Text == "Nam")
                    row["Phai"] = 1;
                else if (comboBoxPhai.Text == "Nữ")
                    row["Phai"] = 0;
                row["Ngaysinh"] = dateTimePickerNgaysinh.Value;
                row["Makhoa"] = comboBoxMakhoa.SelectedValue;
                dt.Rows.Add(row);
                SqlCommand commandInsert = new SqlCommand();
                commandInsert.Connection = conn;
                commandInsert.CommandType = CommandType.Text;
                commandInsert.CommandText = @"Insert Sinhvien (Masv,Holot,Ten,Phai,Ngaysinh,Makhoa) Values (@Masv,@Holot,@Ten,@Phai,@Ngaysinh,@Makhoa)";
                commandInsert.Parameters.Add("@Masv", SqlDbType.VarChar, 5, "Masv");
                commandInsert.Parameters.Add("@Holot", SqlDbType.NVarChar, 30, "Holot");
                commandInsert.Parameters.Add("@Ten", SqlDbType.NVarChar, 10, "Ten");
                commandInsert.Parameters.Add("@Phai", SqlDbType.Bit, 2, "Phai");
                commandInsert.Parameters.Add("@Ngaysinh", SqlDbType.DateTime, 10, "Ngaysinh");
                commandInsert.Parameters.Add("@Makhoa", SqlDbType.VarChar, 5, "Makhoa");
                da.InsertCommand = commandInsert;
                da.Update(dt);
                MessageBox.Show("Bạn đã thêm thành công!", "THÔNG BÁO", MessageBoxButtons.OK);
                Close();
                Sinhvien _Sinhvien = new Sinhvien();
                _Sinhvien.Show();
                Hide();
            }
        }

        private void ThemSinhvien_Load(object sender, EventArgs e)
        {
            connect();//Goi ham ket noi
            getdata();//Goi ham getdata
            
        }

        private void buttonHuy_Click(object sender, EventArgs e)
        {
            textBoxMasinhvien.ResetText();
            textBoxHolot.ResetText();
            textBoxTen.ResetText();
            comboBoxPhai.ResetText();
            dateTimePickerNgaysinh.ResetText();
            comboBoxMakhoa.ResetText();
        }
        
    }
}

Trong form Khoa, bạn thực hiện:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;//Khai bao sql
namespace Chuongtrinhquanlysinhvien
{
    public partial class Khoa : Form
    {
        private SqlConnection conn;//Khai bao bien ket noi
        private DataTable dt = new DataTable("TableKhoa");//Gan dt la table can ket noi
        private SqlDataAdapter da = new SqlDataAdapter(); //Gan da la csdl can ket noi
        private void connect()
        {
            String cn = "Data Source=JackyChan;Initial Catalog=QuanLySinhVien;Integrated Security=True";//chuoi ket noi
            try
            {
                conn = new SqlConnection(cn);//Gan chuoi ket noi
                conn.Open();//Mo ket noi
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể kết nối tới cơ sở dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void getdata()
        {
            SqlCommand command = new SqlCommand();//Khai bao 1 command
            command.Connection = conn;//Ket noi
            command.CommandType = CommandType.Text;//Khai bao kieu command
            command.CommandText = @"Select 
                                           Makhoa as N'Makhoa',
                                           Tenkhoa as N'Tenkhoa'
                                           from Khoa";//Viet cau truy van
            da.SelectCommand = command;//Gan command cho da
            da.Fill(dt);//Nap du lieu cho table
            dataGridViewKhoa.DataSource = dt;//Load du lieu len datagridview
        }
        private void duadulieu()
        {
            textBoxMakhoa.DataBindings.Clear();
            textBoxMakhoa.DataBindings.Add("Text", dataGridViewKhoa.DataSource, "Makhoa");
            textBoxTenkhoa.DataBindings.Clear();
            textBoxTenkhoa.DataBindings.Add("Text", dataGridViewKhoa.DataSource, "Tenkhoa");
        }
        public Khoa()
        {
            InitializeComponent();
        }

        private void buttonThoat_Click(object sender, EventArgs e)
        {
            Quanlysinhvien _Quanlysinhvien = new Quanlysinhvien();
            _Quanlysinhvien.Show();
            Hide();
        }

        private void Khoa_Load(object sender, EventArgs e)
        {
            connect();//Goi ham ket noi
            getdata();//Goi ham getdata
            duadulieu();//Goi ham duadulieu
            textBoxMakhoa.Enabled = false;
        }

        private void buttonThem_Click(object sender, EventArgs e)
        {
            ThemKhoa _ThemKhoa = new ThemKhoa();
            _ThemKhoa.Show();
            Hide();
        }

        private void buttonXoa_Click(object sender, EventArgs e)
        {

            DataRow row = dt.Select("Makhoa = '" + textBoxMakhoa .Text  + "'")[0];
            row.BeginEdit();
            row.Delete();
            row.EndEdit();
            SqlCommand commanDelete = new SqlCommand();
            commanDelete.Connection = conn;
            commanDelete.CommandType = CommandType.Text;
            commanDelete.CommandText = "Delete from Khoa where Makhoa=@Makhoa";
            commanDelete.Parameters.Add("@Makhoa", SqlDbType.VarChar, 5, "Makhoa");
            da.DeleteCommand = commanDelete;
            da.Update(dt);
            MessageBox.Show("Bạn đã xóa thành công!", "THÔNG BÁO", MessageBoxButtons.OK);
        }

        private void buttonSua_Click(object sender, EventArgs e)
        {
            DataRow row = dt.Select("Makhoa = '" + textBoxMakhoa .Text  + "'")[0];
            row.BeginEdit();
            row["Tenkhoa"] = textBoxTenkhoa.Text;
            row.EndEdit();
            SqlCommand commandUpdate = new SqlCommand();
            commandUpdate.Connection = conn;
            commandUpdate.CommandType = CommandType.Text;
            commandUpdate.CommandText = @"Update Khoa set Makhoa=@Makhoa,Tenkhoa=@Tenkhoa Where Makhoa=@Makhoa";
            commandUpdate.Parameters.Add("@Makhoa", SqlDbType.VarChar, 5, "Makhoa");//An khong duoc sua
            commandUpdate.Parameters.Add("@Tenkhoa", SqlDbType.NVarChar, 50, "Tenkhoa");//Sua xong
            da.UpdateCommand = commandUpdate;
            da.Update(dt);
            MessageBox.Show("Bạn đã sửa thành công!", "THÔNG BÁO", MessageBoxButtons.OK);       
        }
    }
}

Trong form Thêm khoa, bạn thực hiện như sau:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;//Khai bao sql
namespace Chuongtrinhquanlysinhvien
{
    public partial class ThemKhoa : Form
    {
        private SqlConnection conn;//Khai bao bien ket noi
        private DataTable dt = new DataTable("TableKhoa");//Gan dt la table can ket noi
        private SqlDataAdapter da = new SqlDataAdapter(); //Gan da la csdl can ket noi
        private bool kt;//khai bao ham kiem tra
        private void connect()
        {
            String cn = "Data Source=JackyChan;Initial Catalog=QuanLySinhVien;Integrated Security=True";//chuoi ket noi
            try
            {
                conn = new SqlConnection(cn);//Gan chuoi ket noi
                conn.Open();//Mo ket noi
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể kết nối tới cơ sở dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void getdata()
        {
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandType = CommandType.Text;
            command.CommandText = "Select * from Khoa";
            da.SelectCommand = command;
            da.Fill(dt);
        }
        private void disconnect()
        {
            conn.Close();//Dong ket noi
            conn.Dispose();//Giai phong tai nguyen
            conn = null;//Huy doi tuong
        }
        private bool kiemtra()//Kiem tra Ma sinh khoa
        {
            kt = true;
            if (textBoxMakhoa .Text  == "")
            {
                MessageBox.Show("Bạn chưa nhập Mã sinh khoa! Mã khoa không được trùng!", "THÔNG BÁO", MessageBoxButtons.OK);
                kt = false;
            }
            return kt;

        }
        public ThemKhoa()
        {
            InitializeComponent();
        }

        private void buttonThoat_Click(object sender, EventArgs e)
        {
            Khoa _Khoa = new Khoa();
            _Khoa.Show();
            Hide();
        }

        private void buttonLuu_Click(object sender, EventArgs e)
        {
                kiemtra();
                if (kt == true)
                {
                    DataRow row = dt.NewRow();
                    row["Makhoa"] = textBoxMakhoa.Text;
                    row["Tenkhoa"] = textBoxTenkhoa.Text;
                    dt.Rows.Add(row);
                    SqlCommand commandInsert = new SqlCommand();
                    commandInsert.Connection = conn;
                    commandInsert.CommandType = CommandType.Text;
                    commandInsert.CommandText = @"Insert Khoa (Makhoa,Tenkhoa) Values (@Makhoa,@Tenkhoa)";
                    commandInsert.Parameters.Add("@Makhoa", SqlDbType.VarChar, 5, "Makhoa");
                    commandInsert.Parameters.Add("@Tenkhoa", SqlDbType.NVarChar, 50, "Tenkhoa");
                    da.InsertCommand = commandInsert;
                    da.Update(dt);
                    MessageBox.Show("Bạn đã thêm thành công!", "THÔNG BÁO", MessageBoxButtons.OK);
                    Close();
                    Khoa _Khoa = new Khoa();
                    _Khoa.Show();
                    Hide();
                }
        }

        private void ThemKhoa_Load(object sender, EventArgs e)
        {
            connect();
            getdata();
        }

        private void buttonHuy_Click(object sender, EventArgs e)
        {
            textBoxMakhoa.ResetText();
            textBoxTenkhoa.ResetText();
        }
    }
}

Trong form Môn học, bạn thực hiện như sau:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Chuongtrinhquanlysinhvien
{
    public partial class Monhoc : Form
    {
        private SqlConnection conn;
        private DataTable dt = new DataTable("TableMonhoc");//Gan dt la table can ket noi
        private SqlDataAdapter da = new SqlDataAdapter(); //Gan da la csdl can ket noi
        private void connect()
        {
            String cn = "Data Source=JackyChan;Initial Catalog=QuanLySinhVien;Integrated Security=True";//chuoi ket noi
            try
            {
                conn = new SqlConnection(cn);//Gan chuoi ket noi
                conn.Open();//Mo ket noi
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể kết nối tới cơ sở dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void getdata()
        {

            SqlCommand command = new SqlCommand();//Khai bao 1 command
            command.Connection = conn;//Ket noi
            command.CommandType = CommandType.Text;//Khai bao kieu command
            command.CommandText = @"Select 
                                           Mamon as N'Mamon',
                                           Tenmon as N'Tenmon',
                                           Dvht as N'Dvht'
                                           from Monhoc";//Viet cau truy van
            da.SelectCommand = command;//Gan command cho da
            da.Fill(dt);//Nap du lieu cho table
            dataGridViewMonhoc.DataSource = dt;//Load du lieu len datagridview
        }
        private void duadulieu()
        {
            textBoxMamon.DataBindings.Clear();
            textBoxMamon.DataBindings.Add("Text", dataGridViewMonhoc.DataSource, "Mamon");
            textBoxTenmon.DataBindings.Clear();
            textBoxTenmon.DataBindings.Add("Text", dataGridViewMonhoc.DataSource, "Tenmon");
            textBoxDvht.DataBindings.Clear();
            textBoxDvht.DataBindings.Add("Text", dataGridViewMonhoc.DataSource, "Dvht");
        }
        public Monhoc()
        {
            InitializeComponent();
        }

        private void Monhoc_Load(object sender, EventArgs e)
        {
            connect();
            getdata();
            duadulieu();
            textBoxMamon.Enabled = false;
        }

        private void buttonThoat_Click(object sender, EventArgs e)
        {
            Quanlysinhvien _Quanlysinhvien = new Quanlysinhvien();
            _Quanlysinhvien.Show();
            Hide();
        }

        private void buttonXoa_Click(object sender, EventArgs e)
        {
            DataRow row = dt.Select("Mamon = '" + textBoxMamon .Text  + "'")[0];
            row.BeginEdit();
            row.Delete();
            row.EndEdit();
            SqlCommand commanDelete = new SqlCommand();
            commanDelete.Connection = conn;
            commanDelete.CommandType = CommandType.Text;
            commanDelete.CommandText = "Delete from Monhoc where Mamon=@Mamon";
            commanDelete.Parameters.Add("@Mamon", SqlDbType.VarChar, 5, "Mamon");
            da.DeleteCommand = commanDelete;
            da.Update(dt);
            MessageBox.Show("Bạn đã xóa thành công!", "THÔNG BÁO", MessageBoxButtons.OK);
        }

        private void buttonSua_Click(object sender, EventArgs e)
        {
            DataRow row = dt.Select("Mamon = '" + textBoxMamon .Text  + "'")[0];
            row.BeginEdit();
            row["Tenmon"] = textBoxTenmon .Text ;
            row["Dvht"] = textBoxDvht.Text;
            row.EndEdit();
            SqlCommand commandUpdate = new SqlCommand();
            commandUpdate.Connection = conn;
            commandUpdate.CommandType = CommandType.Text;
            commandUpdate.CommandText = @"Update Monhoc set Mamon=@Mamon,Tenmon=@Tenmon,Dvht=@Dvht Where Mamon=@Mamon";
            commandUpdate.Parameters.Add("@Mamon", SqlDbType.VarChar, 5, "Mamon");//An khong duoc sua
            commandUpdate.Parameters.Add("@Tenmon", SqlDbType.NVarChar, 50, "Tenmon");//Sua xong
            commandUpdate.Parameters.Add("@Dvht", SqlDbType.Int, 10, "Dvht");
            da.UpdateCommand = commandUpdate;
            da.Update(dt);
            MessageBox.Show("Bạn đã sửa thành công!", "THÔNG BÁO", MessageBoxButtons.OK);       
        }

        private void buttonThem_Click(object sender, EventArgs e)
        {
            ThemMonhoc _ThemMonhoc = new ThemMonhoc();
            _ThemMonhoc.Show();
            Hide ();
        }
    }
}

Trong form Thêm môn học, bạn thực hiện:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Chuongtrinhquanlysinhvien
{
    public partial class ThemMonhoc : Form
    {
        private SqlConnection conn;
        private DataTable dt = new DataTable("TableMonhoc");//Gan dt la table can ket noi
        private SqlDataAdapter da = new SqlDataAdapter(); //Gan da la csdl can ket noi
        private bool kt;
        private void connect()
        {
            String cn = "Data Source=JackyChan;Initial Catalog=QuanLySinhVien;Integrated Security=True";//chuoi ket noi
            try
            {
                conn = new SqlConnection(cn);//Gan chuoi ket noi
                conn.Open();//Mo ket noi
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể kết nối tới cơ sở dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void getdata()
        {
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandType = CommandType.Text;
            command.CommandText = "Select * from Monhoc";
            da.SelectCommand = command;
            da.Fill(dt);
        }
        private bool kiemtra()//Kiem tra Ma Mon hoc
        {
            kt = true;
            if (textBoxMamon.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập Mã môn học! Mã môn không được trùng!", "THÔNG BÁO", MessageBoxButtons.OK);
                kt = false;
            }
            return kt;

        }
        private void disconnect()
        {
            conn.Close();//Dong ket noi
            conn.Dispose();//Giai phong tai nguyen
            conn = null;//Huy doi tuong
        }
        public ThemMonhoc()
        {
            InitializeComponent();
        }

        private void buttonThoat_Click(object sender, EventArgs e)
        {
            Monhoc _Monhoc = new Monhoc();
            _Monhoc.Show();
            Hide();
        }

        private void ThemMonhoc_Load(object sender, EventArgs e)
        {
            connect();
            getdata();
        }

        private void buttonLuu_Click(object sender, EventArgs e)
        {
            kiemtra();
            if (kt == true)
            {
                DataRow row = dt.NewRow();
                row["Mamon"] = textBoxMamon .Text ;
                row["Tenmon"] = textBoxTenmon .Text ;
                row["Dvht"] = textBoxDvht.Text;
                dt.Rows.Add(row);
                SqlCommand commandInsert = new SqlCommand();
                commandInsert.Connection = conn;
                commandInsert.CommandType = CommandType.Text;
                commandInsert.CommandText = @"Insert Monhoc (Mamon,Tenmon,Dvht) Values (@Mamon,@Tenmon,@Dvht)";
                commandInsert.Parameters.Add("@Mamon", SqlDbType.VarChar, 5, "Mamon");
                commandInsert.Parameters.Add("@Tenmon", SqlDbType.NVarChar, 50, "Tenmon");
                commandInsert.Parameters.Add("@Dvht", SqlDbType.Int, 10, "Dvht");
                da.InsertCommand = commandInsert;
                da.Update(dt);
                MessageBox.Show("Bạn đã thêm thành công!", "THÔNG BÁO", MessageBoxButtons.OK);
                Close();
                Monhoc _Monhoc = new Monhoc();
                _Monhoc.Show();
                Hide();
            }
        }

        private void buttonHuy_Click(object sender, EventArgs e)
        {
            textBoxMamon.ResetText();
            textBoxTenmon.ResetText();
            textBoxDvht.ResetText();
        }
    }
}

Trong form Kết quả, bạn thực hiện:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Chuongtrinhquanlysinhvien
{
    public partial class Ketqua : Form
    {
        private SqlConnection conn;
        private DataTable dt = new DataTable("TableKetqua");//Gan dt la table can ket noi
        private SqlDataAdapter da = new SqlDataAdapter(); //Gan da la csdl can ket noi
        private void connect()
        {
            String cn = "Data Source=JackyChan;Initial Catalog=QuanLySinhVien;Integrated Security=True";//chuoi ket noi
            try
            {
                conn = new SqlConnection(cn);//Gan chuoi ket noi
                conn.Open();//Mo ket noi
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể kết nối tới cơ sở dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void getdata()
        {
            SqlCommand command = new SqlCommand();//Khai bao 1 command
            command.Connection = conn;//Ket noi
            command.CommandType = CommandType.Text;//Khai bao kieu command
            command.CommandText = @"Select 
                                           Masv as N'Masv',
                                           Mamon as N'Mamon',
                                           Lanthi as N'Lanthi',
                                           Diem as N'Diem'
                                           from Ketqua";//Viet cau truy van
            da.SelectCommand = command;//Gan command cho da
            da.Fill(dt);//Nap du lieu cho table
            dataGridViewKetqua.DataSource = dt;//Load du lieu len datagridview
        }
        private void duadulieu()
        {
            textBoxMasinhvien.DataBindings.Clear();
            textBoxMasinhvien.DataBindings.Add("Text", dataGridViewKetqua.DataSource, "Masv");
            textBoxMamon.DataBindings.Clear();
            textBoxMamon.DataBindings.Add("Text", dataGridViewKetqua.DataSource, "Mamon");
            textBoxLanthi.DataBindings.Clear();
            textBoxLanthi.DataBindings.Add("Text", dataGridViewKetqua.DataSource, "Lanthi");
            textBoxDiem.DataBindings.Clear();
            textBoxDiem.DataBindings.Add("Text", dataGridViewKetqua.DataSource, "Diem");
        }
        private void disconnect()
        {
            conn.Close();//Dong ket noi
            conn.Dispose();//Giai phong tai nguyen
            conn = null;//Huy doi tuong
        }
        public Ketqua()
        {
            InitializeComponent();
        }

        private void buttonThoat_Click(object sender, EventArgs e)
        {
            Quanlysinhvien _Quanlysinhvien = new Quanlysinhvien();
            _Quanlysinhvien.Show();
            Hide();
        }

        private void Ketqua_Load(object sender, EventArgs e)
        {
            connect();
            getdata();
            duadulieu();
        }

        private void buttonXoa_Click(object sender, EventArgs e)
        {
            DataRow row = dt.Select("Masv = '" + textBoxMasinhvien.Text + "'")[0];
            row.BeginEdit();
            row.Delete();
            row.EndEdit();
            SqlCommand commanDelete = new SqlCommand();
            commanDelete.Connection = conn;
            commanDelete.CommandType = CommandType.Text;
            commanDelete.CommandText = "Delete from Ketqua Where Masv=@Masv";
            commanDelete.Parameters.Add("@Masv", SqlDbType.VarChar, 5, "Masv");
            da.DeleteCommand = commanDelete;
            da.Update(dt);
            MessageBox.Show("Bạn đã xóa thành công!", "THÔNG BÁO", MessageBoxButtons.OK);
        }

        private void buttonSua_Click(object sender, EventArgs e)
        {
            DataRow row = dt.Select("Masv = '" + textBoxMasinhvien .Text  + "'")[0];
            row.BeginEdit();
            row["Mamon"] = textBoxMamon .Text ;
            row["Lanthi"] =textBoxLanthi .Text ;
            row["Diem"] = textBoxDiem.Text;
            row.EndEdit();
            SqlCommand commandUpdate = new SqlCommand();
            commandUpdate.Connection = conn;
            commandUpdate.CommandType = CommandType.Text;
            commandUpdate.CommandText = @"Update Ketqua set Masv=@Masv,Mamon=@Mamon,Lanthi=@Lanthi,Diem=@Diem Where Masv=@Masv";
            commandUpdate.Parameters.Add("@Masv", SqlDbType.VarChar, 5, "Masv");//An khong duoc sua
            commandUpdate.Parameters.Add("@Mamon", SqlDbType.VarChar, 5, "Mamon");
            commandUpdate.Parameters.Add("@Lanthi", SqlDbType.Int ,3, "Lanthi");//Sua xong
            commandUpdate.Parameters.Add("@Diem", SqlDbType.Float , 10, "Diem");
            da.UpdateCommand = commandUpdate;
            da.Update(dt);
            MessageBox.Show("Bạn đã sửa thành công!", "THÔNG BÁO", MessageBoxButtons.OK);   
        }

        private void buttonThem_Click(object sender, EventArgs e)
        {
            ThemKetqua _ThemKetqua = new ThemKetqua();
            _ThemKetqua.Show();
            Hide();
        }
    }
}


Trong form Thêm kết quả, bạn thực hiện như sau:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Chuongtrinhquanlysinhvien
{
    public partial class ThemKetqua : Form
    {
        private SqlConnection conn;
        private DataTable dt = new DataTable("TableKetqua");//Gan dt la table can ket noi
        private DataTable dtsv = new DataTable("TableSinhvien");
        private DataTable dtmonhoc = new DataTable("TableMonhoc");
        private SqlDataAdapter da = new SqlDataAdapter(); //Gan da la csdl can ket noi
        private bool kt;
        private void connect()
        {
            String cn = "Data Source=JackyChan;Initial Catalog=QuanLySinhVien;Integrated Security=True";//chuoi ket noi
            try
            {
                conn = new SqlConnection(cn);//Gan chuoi ket noi
                conn.Open();//Mo ket noi
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể kết nối tới cơ sở dữ liệu!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void getdata()
        {
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandType = CommandType.Text;
            command.CommandText = "Select * from Ketqua";
            da.SelectCommand = command;
            da.Fill(dt);
            //combobox cho Masinhvien
            command.CommandText = "Select * from Sinhvien";
            da.SelectCommand = command;
            da.Fill(dtsv);
            comboBoxMasinhvien.DataSource = dtsv;
            comboBoxMasinhvien.DisplayMember = "Masv";
            comboBoxMasinhvien.ValueMember = "Masv";
            comboBoxMasinhvien.SelectedValue = "Masv";
            
            //Combobox cho Makhoa
            command.CommandText = "Select * from Monhoc";
            da.SelectCommand = command;
            da.Fill(dtmonhoc);
            comboBoxMamon.DataSource = dtmonhoc;
            comboBoxMamon.DisplayMember = "Mamon";
            comboBoxMamon.ValueMember = "Mamon";
            comboBoxMamon.SelectedValue = "Mamon";
        }
        private void disconnect()
        {
            conn.Close();//Dong ket noi
            conn.Dispose();//Giai phong tai nguyen
            conn = null;//Huy doi tuong
        }
        private bool kiemtra()//Kiem tra Ma sinh vien va ma mon
        {
            kt = true;
            if (comboBoxMasinhvien .Text  == "" & comboBoxMamon .Text =="")
            {
                MessageBox.Show("Bạn chưa nhập Mã sinh viên và mã môn!", "THÔNG BÁO", MessageBoxButtons.OK);
                kt = false;
            }
            return kt;

        }
        public ThemKetqua()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Ketqua _Ketqua = new Ketqua();
            _Ketqua.Show();
            Hide();
        }

        private void ThemKetqua_Load(object sender, EventArgs e)
        {
            connect();
            getdata();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            kiemtra();
            if (kt == true)
            {
                DataRow row = dt.NewRow();
                row["Masv"] = comboBoxMasinhvien.SelectedValue  ;
                row["Mamon"] = comboBoxMamon.SelectedValue  ;
                row["Lanthi"] = textBoxLanthi.Text;
                row["Diem"] = textBoxDiem.Text;
                dt.Rows.Add(row);
                SqlCommand commandInsert = new SqlCommand();
                commandInsert.Connection = conn;
                commandInsert.CommandType = CommandType.Text;
                commandInsert.CommandText = @"Insert Ketqua (Masv,Mamon,Lanthi,Diem) Values (@Masv,@Mamon,@Lanthi,@Diem)";
                commandInsert.Parameters.Add("@Masv", SqlDbType.VarChar, 5, "Masv");
                commandInsert.Parameters.Add("@Mamon", SqlDbType.VarChar, 5, "Mamon");
                commandInsert.Parameters.Add("@Lanthi", SqlDbType.Int ,3, "Lanthi");
                commandInsert.Parameters.Add("@Diem", SqlDbType.Float, 10, "Diem");
                da.InsertCommand = commandInsert;
                da.Update(dt);
                MessageBox.Show("Bạn đã thêm thành công!", "THÔNG BÁO", MessageBoxButtons.OK);
                Close();
                Ketqua  _Ketqua = new Ketqua ();
                _Ketqua.Show();
                Hide();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            comboBoxMasinhvien.ResetText();
            comboBoxMamon.ResetText();
            textBoxLanthi.ResetText();
            textBoxDiem.ResetText();
        }
    }
}

Chúc bạn thành công!

Không chỉ là đam mê!