I want to read some records from xml file using LINQ and bind to datagridview control
XDocument xdoc = XDocument.Load("Simple.xml");var
query1 = from books
in xdoc.Elements("NewDataSet").Elements("Table")
select books;
DataTable dttemp =
new DataTable();
dttemp = query1.CopyToDataTable();
dataGridView1.DataSource = dttemp;
but in my situation i dont know how many columns will coming(because based on application situation it'll create different number of column name so that i cant specify column names) if i execute the the same query then it will not bind anything instead of
bind the records i write one for loop
jeyaseelan@a...
Contributor
5124 Points
2025 Posts
bind records to datagridview using LINQ?
Jan 27, 2009 12:41 PM|LINK
Hi to all,
I want to read some records from xml file using LINQ and bind to datagridview control
XDocument xdoc = XDocument.Load("Simple.xml");var query1 = from books in xdoc.Elements("NewDataSet").Elements("Table")
select books; DataTable dttemp = new DataTable();dttemp = query1.CopyToDataTable();
dataGridView1.DataSource = dttemp;
but in my situation i dont know how many columns will coming(because based on application situation it'll create different number of column name so that i cant specify column names) if i execute the the same query then it will not bind anything instead of bind the records i write one for loop
foreach (DataRow p in query1 ){
label1.Text += p.Field<string>("name");label1.Text += "-";}
now the control comes inside of for loop so it can retrieve data but while binding to gridview this will not bind properly.
Experts please tell me without specifying select clause how to bind the columns to dgv.
J.Jeyaseelan