简体   繁体   中英

DataGridView - Fill DataSet with Linq

I want a DataSet get filled with a particular piece of Xml. This is the Xml Code:

<?xml version="1.0" standalone="yes"?>
<Courses>
    <Course id="3306">
        <Student>One</Student>
        <Student>Two</Student>
        <Student>Three</Student>
        <Student>Four</Student>
    </Course>
</Courses>

Of course there will be more <Course> -Tags. Now I want one Course to fill the DataSet who shows itself in a DataGridView.
E. g. "Show all Students WHERE Course-ID == '3306' "
Now I thought about Linq but I really do not know how to to it. Maybe Linq is a wrong start...
For other "unfiltered" Lists I use

string filePath = "AllStudents.Xml";
dsCourseList.ReadXml(filePath);
dgvCourseList.DataSource = dsCourseList; //DataSet
dgvCourseList.DataMember = "Student";

Maybe someone could help me.

Bind directly to the LINQ object.

var results = myCourses.Where(c=>c.ID == courseId);

dgvCourseList.DataSource = results.ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM