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
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
But it'll display some unrelated columns like this
EmptySequence, FirstAttribute, HasAttributes, HasElements, IsEmpty, LastAttribute, Name, NodeType, Value, FirstNode, LastNode but in my xml file i have only 4 columns such as Name, Id, Age and Sex.
Could you please tell me how to select all columns without specifying column names because number of columns will vary for different situation.
Please help me. You are the only person responsing me. Thanks again.
Any doubts please feel free to ask me. If this post is answer of your question then don't forgot to Click "Mark As Answer".
J.Jeyaseelan
But it'll display some unrelated columns like this
EmptySequence, FirstAttribute, HasAttributes, HasElements, IsEmpty, LastAttribute, Name, NodeType, Value, FirstNode, LastNode but in my xml file i have only 4 columns such as Name, Id, Age and Sex.
Could you please tell me how to select all columns without specifying column names because number of columns will vary for different situation.
Please help me. You are the only person responsing me. Thanks again.
mudassarkhan thanks for your response.
But in my case i should read from xml file with some filter condition, if we are using Dataset then no use of LINQ to XML.
This is possible by Dynamic Linq, i'm trying by this way, could you please help me to solve this problem?
Any doubts please feel free to ask me. If this post is answer of your question then don't forgot to Click "Mark As Answer".
J.Jeyaseelan
mudassarkhan thanks for your response.
But in my case i should read from xml file with some filter condition, if we are using Dataset then no use of LINQ to XML.
This is possible by Dynamic Linq, i'm trying by this way, could you please help me to solve this problem?
</div>
But how can you query withoutcolumn names
And if you only need to bind the dataset to gridview then why you want link in between
you can query the dataset too. I still don't get what you are trying to achieve
In SQL we can write a query like select * from table_name here we dont specify any column names in
mycase depending upon user the number of column should vary so that i expect without specifying column name and select all columns from the xml file. Or Specifying the column dynamically that is add all column names to a string variable and execute this
string query by LINQ
And if you only need to bind the dataset to gridview then why you want link in between
In my case i want to read some records from xml file with some filter conditions after that i assign this record to DataSet for further processing and bind into dgv.
you can query the dataset too. I still don't get what you are trying to achieve
But in mycase the xml file size may be 100MB then reading all data to a dataset object then the performance will affect so instead of that first by some filter conditions i read the data and assign to Dataset and bind into dgv.
I thiink now you are cleared
Any doubts please feel free to ask me. If this post is answer of your question then don't forgot to Click "Mark As Answer".
J.Jeyaseelan
In SQL we can write a query like select * from table_name here we dont specify any column names in
mycase depending upon user the number of column should vary so that i expect without specifying column name and select all columns from the xml file. Or Specifying the column dynamically that is add all column names to a string variable and execute this
string query by LINQ
But before you said you want to remove some columns which you dont need In Select * query every column will come so without column name you cannot do that
Only way I can suggest is Hide the Column in teh GridView you dont want
In SQL we can write a query like select * from table_name here we dont specify any column names in
mycase depending upon user the number of column should vary so that i expect without specifying column name and select all columns from the xml file. Or Specifying the column dynamically that is add all column names to a string variable and execute this
string query by LINQ
But before you said you want to remove some columns which you dont need In Select * query every column will come so without column name you cannot do that
Only way I can suggest is Hide the Column in teh GridView you dont want
In SQL we can write a query like select * from table_name here we dont specify any column names in
mycase depending upon user the number of column should vary so that i expect without specifying column name and select all columns from the xml file. Or Specifying the column dynamically that is add all column names to a string variable and execute this
string query by LINQ
But before you said you want to remove some columns which you dont need In Select * query every column will come so without column name you cannot do that
Only way I can suggest is Hide the Column in teh GridView you dont want
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
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: bind records to datagridview using LINQ?
Jan 27, 2009 01:37 PM|LINK
If you want yo bind All columns just set Autogeneratecolumns=true
and do
dataGridView1.DataSource = dttemp;
dataGridView1.DataBind(); // this is missing is ur code
Contact me
jeyaseelan@a...
Contributor
5124 Points
2025 Posts
Re: bind records to datagridview using LINQ?
Jan 27, 2009 02:17 PM|LINK
mudassarkhan thanks for your response.
But it'll display some unrelated columns like this
EmptySequence, FirstAttribute, HasAttributes, HasElements, IsEmpty, LastAttribute, Name, NodeType, Value, FirstNode, LastNode but in my xml file i have only 4 columns such as Name, Id, Age and Sex.
Could you please tell me how to select all columns without specifying column names because number of columns will vary for different situation.
Please help me. You are the only person responsing me. Thanks again.
J.Jeyaseelan
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: bind records to datagridview using LINQ?
Jan 27, 2009 02:40 PM|LINK
I will suggest do
ds.ReadXML
that's a good approach
atleast try once to see if solves the issue
Contact me
jeyaseelan@a...
Contributor
5124 Points
2025 Posts
Re: bind records to datagridview using LINQ?
Jan 27, 2009 02:51 PM|LINK
mudassarkhan thanks for your response.
But in my case i should read from xml file with some filter condition, if we are using Dataset then no use of LINQ to XML.
This is possible by Dynamic Linq, i'm trying by this way, could you please help me to solve this problem?
J.Jeyaseelan
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: bind records to datagridview using LINQ?
Jan 27, 2009 03:11 PM|LINK
But how can you query withoutcolumn names
And if you only need to bind the dataset to gridview then why you want link in between
you can query the dataset too. I still don't get what you are trying to achieve
Contact me
jeyaseelan@a...
Contributor
5124 Points
2025 Posts
Re: bind records to datagridview using LINQ?
Jan 28, 2009 01:55 AM|LINK
mudassarkhan thanks for your response.
But how can you query withoutcolumn names
In SQL we can write a query like select * from table_name here we dont specify any column names in mycase depending upon user the number of column should vary so that i expect without specifying column name and select all columns from the xml file. Or Specifying the column dynamically that is add all column names to a string variable and execute this string query by LINQ
And if you only need to bind the dataset to gridview then why you want link in between
In my case i want to read some records from xml file with some filter conditions after that i assign this record to DataSet for further processing and bind into dgv.
you can query the dataset too. I still don't get what you are trying to achieve
But in mycase the xml file size may be 100MB then reading all data to a dataset object then the performance will affect so instead of that first by some filter conditions i read the data and assign to Dataset and bind into dgv.
I thiink now you are cleared
J.Jeyaseelan
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: bind records to datagridview using LINQ?
Jan 28, 2009 03:51 AM|LINK
But before you said you want to remove some columns which you dont need In Select * query every column will come so without column name you cannot do that
Only way I can suggest is Hide the Column in teh GridView you dont want
I think this shud solve ur issue
Let me know ifContact me
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: bind records to datagridview using LINQ?
Jan 28, 2009 03:51 AM|LINK
But before you said you want to remove some columns which you dont need In Select * query every column will come so without column name you cannot do that
Only way I can suggest is Hide the Column in teh GridView you dont want
I think this shud solve ur issue
Let me know if you want to doContact me
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: bind records to datagridview using LINQ?
Jan 28, 2009 03:51 AM|LINK
But before you said you want to remove some columns which you dont need In Select * query every column will come so without column name you cannot do that
Only way I can suggest is Hide the Column in teh GridView you dont want
I think this shud solve ur issue
Let me know if you want to do thisContact me