'Data output to datagrid from different tables

there is a database in which tables related to each other are stored, there is a table of students (student), groups (course) and grades(estimation). It is necessary to display columns by subjects in DATAGRID, all students from groups and their grades by subject enter image description here

I output the columns as follows

private void LoadColumn()
        {
            db.OpenConnection();
            OleDbCommand command = new OleDbCommand($"select * from predmets where `id_course` = {group_id}", db.GetConnection());
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    DataGridTextColumn textColumn = new DataGridTextColumn()
                    {
                        Binding = new Binding("predmet_id"),
                        Header = GetPredmetId(reader.GetInt32(2)),
                        IsReadOnly = false
                    };
                    GroupDataGrid.Columns.Add(textColumn);
                }
            }
            db.CloseConnection();
        }

and the students

db dbase = new db();
            dbase.OpenConnection();
            OleDbCommand command = new OleDbCommand($"select * from student where `course_id` = {group_id}", dbase.GetConnection());
            using (var reader = command.ExecuteReader())
                while (reader.Read())
                {
                    Grades.Add(new Grade()
                    {
                        id = reader.GetInt32(0),
                        student_name = reader.GetString(2),
                        grade = GetGrade(group_id, reader.GetInt32(0), GetPredmet(group_id)),
                        predmet_id = GetPredmet(group_id)
                    });
                }
            GroupDataGrid.ItemsSource = Grades;
            dbase.CloseConnection();

there is a Datagrid

<DataGrid Grid.Row="1"
                  Name="GroupDataGrid"
                  MaxColumnWidth="400"
                  ColumnWidth="*"
                  CanUserAddRows="False"
                  SelectionUnit="FullRow"
                  SelectionMode="Single" 
                  Loaded="GroupDataGrid_Loaded"
                  AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding id}" Header="Id" Visibility="Hidden"/>
                <DataGridTextColumn Binding="{Binding student_name}" Header="ФИО" IsReadOnly="True"/>
            </DataGrid.Columns>
        </DataGrid>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source