C# Student Management System - Student List (Different Grades)

C# student management system - student list (query function)

The specific layout and function realization will not be written, it is the same as the class list, please refer to the last article for details. Different grades have the same class name. In order to distinguish the classes of which grade, I mainly want to write down the implementation of adding the corresponding grade suffix after the class. This is also a problem that Xiaobai has worked hard for a long time. . .
Insert image description here

Combine classes and grades

At this time, you must first determine that the number of student columns is not empty, traverse all the rows, get the class name and grade name, and then assign them to the class name.

 string sql = "SELECT class.cid,class.cname, grade.gname FROM class INNER JOIN grade ON class.gid = grade.gid";
 DataTable dtclass = sqlhelper.getDataTable(sql);
//将班级和年级组合起来
            if (dt.Rows.Count > 0)
            {
    
    
                foreach (DataRow drzuhe in dt.Rows)
                {
    
    
                    string classname = drzuhe["cname"].ToString();
                    string gradename = drzuhe["gname"].ToString();
                    drzuhe["cname"] = classname + "--" + gradename;
                }
            } 
            //不显示gname这列
            dgvclass.AutoGenerateColumns = false;

The remaining parts are exactly the same, and the query results are as follows:
Insert image description here

Guess you like

Origin blog.csdn.net/qq_42740834/article/details/105795920