read data from xml file using LINQ?http://forums.asp.net/t/1371898.aspx/1?read+data+from+xml+file+using+LINQ+Tue, 20 Jan 2009 14:32:07 -050013718982870305http://forums.asp.net/p/1371898/2870305.aspx/1?read+data+from+xml+file+using+LINQ+read data from xml file using LINQ? <p>Hi to all,</p> <p>I have a XML file i want to select records from that but i dont know what are the columns is there because while runtime the xml file columns are differ, so how can i write the query for this situation using LINQ?</p> <p>Experts please help me.</p> <p>&nbsp;</p> 2009-01-16T04:44:07-05:002871047http://forums.asp.net/p/1371898/2871047.aspx/1?Re+read+data+from+xml+file+using+LINQ+Re: read data from xml file using LINQ? <p>Well an XML document does not have records or columns, instead it has nodes like element nodes, attribute nodes, comment nodes, text nodes. You can read out such nodes and determine the names if you want. Here is an example that recursively processes the elements nodes, starting with the root element and then processing the child elements:</p> <p>With the XML being</p> <p>&nbsp;<pre class="prettyprint">&lt;root&gt; &lt;foo&gt; &lt;bar&gt;bar 1&lt;/bar&gt; &lt;/foo&gt; &lt;foo&gt; &lt;bar&gt;bar 2&lt;/bar&gt; &lt;/foo&gt; &lt;/root&gt;</pre>&nbsp;&nbsp; <P mce_keep="true">&nbsp;</P> <P>this C# snippet</P><pre class="prettyprint"> <SPAN class=kwd>static void</SPAN> Main() { XDocument doc = XDocument.Load(@<SPAN class=st>"..\..\XMLFile1.xml"</SPAN>); ShowChildren(doc.Root); } <SPAN class=kwd>static void</SPAN> ShowChildren(XElement el) { ShowChildren(el, <SPAN class=st>""</SPAN>); } <SPAN class=kwd>static void</SPAN> ShowChildren(XElement el, <SPAN class=kwd>string</SPAN> indent) { Console.WriteLine(indent + <SPAN class=st>"Element named '{0}'."</SPAN>, el.Name); <SPAN class=kwd>foreach</SPAN> (XElement childEl <SPAN class=kwd>in</SPAN> el.Elements()) { ShowChildren(childEl, indent + <SPAN class=st>" "</SPAN>); } }</pre> </p> <p>&nbsp;outputs</p> <p>Element named 'root'.<br> &nbsp; Element named 'foo'.<br> &nbsp;&nbsp;&nbsp; Element named 'bar'.<br> &nbsp; Element named 'foo'.<br> &nbsp;&nbsp;&nbsp; Element named 'bar'.</p> <p>If that does not help then you need to show us samples of the XML you want to process and tell us exactly which nodes you are interested in.</p> 2009-01-16T11:13:15-05:002871086http://forums.asp.net/p/1371898/2871086.aspx/1?Re+read+data+from+xml+file+using+LINQ+Re: read data from xml file using LINQ? <p><strong>Martin_Honnen,</strong></p> <p><strong>Thanks for your response.</strong></p> <p><strong>Actually this is my xml file, i want to retrieve these data and bind to datagridview control</strong></p> <p>&lt;?xml version=&quot;1.0&quot; standalone=&quot;yes&quot;?&gt;<br> &lt;NewDataSet&gt;<br> &nbsp; &lt;xs:schema id=&quot;NewDataSet&quot; xmlns=&quot;&quot; xmlns:xs=&quot;<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>&quot; xmlns:msdata=&quot;urn:schemas-microsoft-com:xml-msdata&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &lt;xs:element name=&quot;NewDataSet&quot; msdata:IsDataSet=&quot;true&quot; msdata:MainDataTable=&quot;Table&quot; msdata:UseCurrentLocale=&quot;true&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:complexType&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:choice minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element name=&quot;Table&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:complexType&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:sequence&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element name=&quot;id&quot; type=&quot;xs:int&quot; minOccurs=&quot;0&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element name=&quot;name&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:element name=&quot;age&quot; type=&quot;xs:int&quot; minOccurs=&quot;0&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:sequence&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:complexType&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:element&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:choice&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xs:complexType&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/xs:element&gt;<br> &nbsp; &lt;/xs:schema&gt;<br> &nbsp; &lt;Table&gt;<br> &nbsp;&nbsp;&nbsp; &lt;id&gt;1&lt;/id&gt;<br> &nbsp;&nbsp;&nbsp; &lt;name&gt;mary&lt;/name&gt;<br> &nbsp;&nbsp;&nbsp; &lt;age&gt;23&lt;/age&gt;<br> &nbsp; &lt;/Table&gt;<br> &nbsp; &lt;Table&gt;<br> &nbsp;&nbsp;&nbsp; &lt;id&gt;2&lt;/id&gt;<br> &nbsp;&nbsp;&nbsp; &lt;name&gt;joseph&lt;/name&gt;<br> &nbsp;&nbsp;&nbsp; &lt;age&gt;34&lt;/age&gt;<br> &nbsp; &lt;/Table&gt;</p> <p>I write this method in the code behind</p> <font size="2"></font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> Method4()</font><font size="2"> <p>{</p> <p></font><font color="#0000ff" size="2">try</p> </font><font size="2"> <p>{</p> </font><font color="#2b91af" size="2">XDocument</font><font size="2"> xdoc = </font> <font color="#2b91af" size="2">XDocument</font><font size="2">.Load(</font><font color="#a31515" size="2">&quot;Simple.xml&quot;</font><font size="2">);</font><font size="2"> <p>&nbsp;</p> </font><font color="#2b91af" size="2">DataSet</font><font size="2"> ds = </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">DataSet</font><font size="2">();</font><font size="2"> <p></font><font color="#2b91af" size="2">DataTable</font><font size="2"> dt = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">DataTable</font><font size="2">();</p> </font><font color="#0000ff" size="2">var</font><font size="2"> MyOutput = </font> <font color="#0000ff" size="2">from</font><font size="2"> MyTable </font><font color="#0000ff" size="2">in</font><font size="2"> xdoc.Elements(</font><font color="#a31515" size="2">&quot;NewDataSet&quot;</font><font size="2">).Elements(</font><font color="#a31515" size="2">&quot;Table&quot;</font><font size="2">)</font><font size="2"> <p>&nbsp;</p> </font><font color="#0000ff" size="2">select</font><font size="2"> MyTable;</font><font size="2"> <p>&nbsp;</p> <p>&nbsp;</p> <p>dt = MyOutput.CopyToDataTable();</p> <p>dataGridView1.DataSource = dt;</p> <p></font><font color="#008000" size="2">//BindingSource bs = new BindingSource();</p> </font><font size="2"> <p></font><font color="#008000" size="2">//bs.DataSource = MyOutput;</p> </font><font size="2"> <p></font><font color="#008000" size="2">//dataGridView1.DataSource = bs;</p> </font><font size="2"> <p>&nbsp;</p> <p>}</p> </font><font color="#0000ff" size="2">catch</font><font size="2"> (</font><font color="#2b91af" size="2">Exception</font><font size="2"> ex)</font><font size="2"> <p>{</p> <p>label1.Text = ex.Message;</p> <p>}</p> <p>}</p> <p>but the output like this</p> <span style="font-size:10pt; color:blue; font-family:'Courier New'">&nbsp;</span><span style="font-size:10pt; color:blue; font-family:'Courier New'"> <p> <table class="MsoTableGrid" cellspacing="0" cellpadding="0" border="1" class="MsoTableGrid" style="border-right:medium none; border-top:medium none; border-left:medium none; border-bottom:medium none; border-collapse:collapse"> <tbody> <tr style=""> <td class="" valign="top" width="118" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:windowtext 1pt solid; padding-left:5.4pt; padding-bottom:0in; border-left:windowtext 1pt solid; width:88.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">EmptySequence</span></td> <td class="" valign="top" width="126" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:windowtext 1pt solid; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:94.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">FirstAttribute</span></td> <td class="" valign="top" width="118" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:windowtext 1pt solid; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:88.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">HasAttributes</span></td> <td class="" valign="top" width="116" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:windowtext 1pt solid; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:86.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">HasElements</span></td> <td class="" valign="top" width="111" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:windowtext 1pt solid; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:83.4pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">IsEmpty</span></td> </tr> <tr style=""> <td class="" valign="top" width="118" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:#ece9d8; padding-left:5.4pt; padding-bottom:0in; border-left:windowtext 1pt solid; width:88.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">&nbsp;</span></td> <td class="" valign="top" width="126" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:#ece9d8; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:94.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">&nbsp;</span></td> <td class="" valign="top" width="118" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:#ece9d8; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:88.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">(UnCheckbox)</span></td> <td class="" valign="top" width="116" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:#ece9d8; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:86.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">(Checkedbox)</span></td> <td class="" valign="top" width="111" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:#ece9d8; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:83.4pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">(UnCheckbox)</span></td> </tr> <tr style=""> <td class="" valign="top" width="118" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:#ece9d8; padding-left:5.4pt; padding-bottom:0in; border-left:windowtext 1pt solid; width:88.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">&nbsp;</span></td> <td class="" valign="top" width="126" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:#ece9d8; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:94.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">&nbsp;</span></td> <td class="" valign="top" width="118" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:#ece9d8; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:88.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">(UnCheckbox)</span></td> <td class="" valign="top" width="116" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:#ece9d8; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:86.85pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">(Checkedbox)</span></td> <td class="" valign="top" width="111" style="border-right:windowtext 1pt solid; padding-right:5.4pt; border-top:#ece9d8; padding-left:5.4pt; padding-bottom:0in; border-left:#ece9d8; width:83.4pt; padding-top:0in; border-bottom:windowtext 1pt solid; background-color:transparent"> <span style="font-size:10pt; color:blue; font-family:'Courier New'">(UnCheckbox)</span></td> </tr> </tbody> </table> </p> <p>&nbsp;</p> <p>why it looks like this, could you please tell me the solution?</span></p> </font> 2009-01-16T11:40:55-05:002871117http://forums.asp.net/p/1371898/2871117.aspx/1?Re+read+data+from+xml+file+using+LINQ+Re: read data from xml file using LINQ? <p>Why do you want to use LINQ to XML with that XML document? It is tailor made for simply reading it into a DataSet with ReadXml e.g.</p> <p>DataSet ds = new DataSet();</p> <p>ds.ReadXml(&quot;Simple.xml&quot;);</p> <p>dataGridView1.DataSource = ds.Tables[0];</p> 2009-01-16T11:57:58-05:002871146http://forums.asp.net/p/1371898/2871146.aspx/1?Re+read+data+from+xml+file+using+LINQ+Re: read data from xml file using LINQ? <p><strong>Martin_Honnen,</strong></p> <p><strong>Thanks for your response.</strong></p> <p><strong>Actually this is my task(read xml data by LINQ and bind to dgv), could you please tell me how to do this?</strong></p> 2009-01-16T12:13:04-05:002871203http://forums.asp.net/p/1371898/2871203.aspx/1?Re+read+data+from+xml+file+using+LINQ+Re: read data from xml file using LINQ? <p>Martin_Honnen, thanks for ur response.</p> <p>If i do like this, </p> <p>DataSet ds = new DataSet();</p> <p>ds.ReadXml(&quot;Simple.xml&quot;);</p> <p>dataGridView1.DataSource = ds.Tables[0];</p> <p>now i want to filter the data from ds using LINQ could you please tell me how to write the query without mention column name?</p> 2009-01-16T12:36:13-05:002871213http://forums.asp.net/p/1371898/2871213.aspx/1?Re+read+data+from+xml+file+using+LINQ+Re: read data from xml file using LINQ? <p>Well if you know which elements you want to access then you can easily create an anonymous type for instance:</p> <p>&nbsp;<pre class="prettyprint">XDocument doc = XDocument.Load(&quot;XMLFile1.xml&quot;); dataGridView1.DataSource = (from table in doc.Root.Elements(&quot;Table&quot;) select new { Id = (int)table.Element(&quot;id&quot;), Name = (string)table.Element(&quot;name&quot;), Age = (int)table.Element(&quot;age&quot;) }).ToList();</pre> </p> <p>&nbsp;</p> <p>I realize that does not help if your original requirement of not knowing the XML structure is still valid.</p> 2009-01-16T12:39:43-05:002871244http://forums.asp.net/p/1371898/2871244.aspx/1?Re+read+data+from+xml+file+using+LINQ+Re: read data from xml file using LINQ? <p><strong>Martin_Honnen</strong> </p> <p>thanks for ur response.</p> <p>Actually i dont know how many columns will come on xml file so cant use this query</p> <p>select <span class="kwd"><font color="#0000ff">new</font></span><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong><u><em> Id = (<span class="kwd"><font color="#0000ff">int</font></span>)table.Element(<span class="st"><font color="#ff0000">&quot;id&quot;</font></span>),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name = (<span class="kwd"><font color="#0000ff">string</font></span>)table.Element(<span class="st"><font color="#ff0000">&quot;name&quot;</font></span>),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Age = (<span class="kwd"><font color="#0000ff">int</font></span>)table.Element(<span class="st"><font color="#ff0000">&quot;age&quot;</font></span>)</em></u></strong><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }).ToList();</p> <p>so i accept ur idea that is </p> <p>DataSet ds = new DataSet();</p> <p>ds.ReadXml(&quot;Simple.xml&quot;);</p> <p>dataGridView1.DataSource = ds.Tables[0];</p> <p>now i want to filter the records from ds by LINQ query without mentioning column name(column name will com from combobox)</p> <p>could you please tell me how to do this?</p> <p>Thanks in advance.</p> 2009-01-16T12:47:29-05:002875495http://forums.asp.net/p/1371898/2875495.aspx/1?Re+read+data+from+xml+file+using+LINQ+Re: read data from xml file using LINQ? Martin_Honnen can you please answer my question? 2009-01-19T03:57:52-05:002876476http://forums.asp.net/p/1371898/2876476.aspx/1?Re+read+data+from+xml+file+using+LINQ+Re: read data from xml file using LINQ? <p>Martin Actually i found one code</p> <h1><a class="" name="_Dynamic_Expression_API"></a><span style="">Dynamic Expression API</span></h1> <p class="MsoNormal"><a class="" name="_The_ParseLambda_Methods"></a>The Dynamic Expression API is brought into scope by using (importing) the <span class="SpellE"><span class="CodeFragment">System.Linq.Dynamic</span></span> namespace. Below is an example of applying the Dynamic Expression API to a LINQ to SQL data source.</p> <p class="Code"><span class="SpellE"><span class="GramE"><span style="color:blue">var</span></span></span> query =<br> &nbsp;&nbsp;&nbsp; <span class="SpellE">db.Customers</span>.<br> &nbsp;&nbsp;&nbsp; <span class="GramE">Where(</span><span style="color:#a31515">&quot;City = @0 and <span class="SpellE"> Orders.Count</span> &gt;= @1&quot;</span>, <span style="color:#a31515">&quot;London&quot;</span>, 10).<br> &nbsp;&nbsp;&nbsp; <span class="SpellE"><span class="GramE">OrderBy</span></span><span class="GramE">(</span><span style="color:#a31515">&quot;<span class="SpellE">CompanyName</span>&quot;</span>).<br> &nbsp;&nbsp;&nbsp; <span class="GramE">Select(</span><span style="color:#a31515">&quot;new(<span class="SpellE">CompanyName</span> as Name, Phone)&quot;</span>);</p> <p class="Code">but this will work if i include dbml file. if i change the query like my format </p> <p><font size="2"></font><font color="#2b91af" size="2">DataTable</font><font size="2"> dtTemp = </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">DataTable</font><font size="2">();</font></p> <p><font size="2"></font><font color="#0000ff" size="2">var query =<br> &nbsp;&nbsp;&nbsp; <font color="#000000">dtTemp.AsEnumerable().</font><br> &nbsp;&nbsp;&nbsp; <u><strong>Where(&quot;Name= @0 &quot;, &quot;yova&quot;).</strong></u><br> &nbsp;&nbsp;&nbsp; OrderBy(&quot;Name&quot;).<br> &nbsp;&nbsp;&nbsp; Select(&quot;new(Name)&quot;);</font></p> <font size="2"> <p>dtTemp = query.CopyToDataTable();</p> <p>but it raise the following error at bolded line</p> <p>Error&nbsp;1&nbsp;'System.Data.EnumerableRowCollection&lt;System.Data.DataRow&gt;' does not contain a definition for 'Where' and the best extension method overload 'System.Linq.Dynamic.DynamicQueryable.Where(System.Linq.IQueryable, string, params object[])' has some invalid arguments&nbsp;D:\\Linq\LINQ_Final_POC\LINQ Demo\WindowsFormsApplication1\MyWork\Form1.cs&nbsp;98&nbsp;29&nbsp;WindowsFormsApplication1</p> <p>Error&nbsp;2&nbsp;Instance argument: cannot convert from 'System.Data.EnumerableRowCollection&lt;System.Data.DataRow&gt;' to 'System.Linq.IQueryable'&nbsp;D:\\Linq\LINQ_Final_POC\LINQ Demo\WindowsFormsApplication1\MyWork\Form1.cs&nbsp;98&nbsp;29&nbsp;WindowsFormsApplication1</p> <p>Error&nbsp;3&nbsp;Argument '3': cannot convert from 'string' to 'object[]'&nbsp;D:\\Linq\LINQ_Final_POC\LINQ Demo\WindowsFormsApplication1\MyWork\Form1.cs&nbsp;98&nbsp;29&nbsp;WindowsFormsApplication1</p> <p>Experts please help me, how to do this?<br> </p> </font> <p class="Code">&nbsp;</p> 2009-01-19T11:00:15-05:002879110http://forums.asp.net/p/1371898/2879110.aspx/1?Re+read+data+from+xml+file+using+LINQ+Bug+Re: read data from xml file using LINQ?-Bug? <p>I think it's <strong>not possible</strong> or it may be a <strong>bug</strong>&nbsp;in LINQ </p> <p>because last two days i'm trying to write a dynamic query to dataset but there is no solution in net and no help document realted to Dynamic Linq to DataSet.</p> <p>Experts have any idea?</p> 2009-01-20T12:04:43-05:002879375http://forums.asp.net/p/1371898/2879375.aspx/1?Re+read+data+from+xml+file+using+LINQ+Re: read data from xml file using LINQ? <p align="left">My task is i have a dataset with N number of records, now i want to retrieve some records from there by user input but in my case i dont know the column name and datatypes of the column because based on situation different no. of column will be added in dataset, so i tried with dynamic linq query by this article <a title="http://aspalliance.com/1569_Dynamic_LINQ_Part_1_Using_the_LINQ_Dynamic_Query_Library.all" href="http://aspalliance.com/1569_Dynamic_LINQ_Part_1_Using_the_LINQ_Dynamic_Query_Library.all"> http://aspalliance.com/1569_Dynamic_LINQ_Part_1_Using_the_LINQ_Dynamic_Query_Library.all</a>&nbsp;they wrote for SQL</p> <p align="left">like below</p> <p align="left">&nbsp;</p> <p align="left">Dim Northwind as new NorthwindDataContext</p> <p align="left">Dim query = From P in Northwind.Products where (&quot;CategoryId==2 And unitprice&gt;3&quot;).OrderBy(&quot;SupplierId&quot;)</p> <p align="left">&nbsp;</p> <p align="left">I convert the same syntax to DataSet </p> <p align="left">&nbsp;</p> <font color="#0000ff" size="2"><strong><font style="background-color:#ffff00">var</font></strong></font><strong><font style="background-color:#ffff00"><font size="2"> query = ds.Tables[0].AsEnumerable().AsQueryable().Where(</font><font color="#a31515" size="2">&quot;name==yova&quot;</font><font size="2">).OrderBy(</font><font color="#a31515" size="2">&quot;name&quot;</font></font></strong><font size="2"><strong><font style="background-color:#ffff00">);</font></strong></font><font size="2"> <p>dataGridView1.DataSource = query;</p> <p align="left">but it raise an error as <font size="3"><strong>No property or field 'name' exists in type 'DataRow' (at index 0)</strong></font></p> <p align="left">&nbsp;</p> <p>actually error thrown in yellow colored line, but the column &quot;name&quot; is exist in the DataSet. I tried with different column names but no luck!</p> <p align="left">&nbsp;</p> <p align="left">What is the problem and how to solve this error experts please explain, i think it's problem in LINQ?</font></p> 2009-01-20T14:32:07-05:00