简体   繁体   中英

how to import data from a xml file into datagrid view using linq?

Im using c# .net , windows form application. I have a XML file which contains two columns and some rows of data. now i have to fill this data into a data grid view. I want to use LINQ.

You can try something like this:

        // choose you filename there
        XElement xElement = XElement.Load("file.xml");
        // choose appropriate properties
        dataGridView1.DataSource = (from el in xElement.Elements()
                  select new { a = el.Name.ToString(), b = "Whatever"}).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