ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Add multiple Where condition in Linq query using C# and VB.Net<p>I will get back to you soon.</p>https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/Sun, 02 Dec 2018 23:08:38 GMTAdd multiple Where condition in Linq query using C# and VB.Net<p>Hey <a class="username" rel="yogesjoshi">yogesjoshi</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;asp:GridView ID=&#34;GridView1&#34; runat=&#34;server&#34; /&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:GridView ID=&#34;GridView2&#34; runat=&#34;server&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan=&#34;2&#34; align=&#34;center&#34;&gt; &lt;asp:GridView ID=&#34;GridView3&#34; Caption=&#34;&lt;b&gt;Output&lt;/b&gt;&#34; runat=&#34;server&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add(&#34;Department&#34;); dt.Columns.Add(&#34;name&#34;); dt.Columns.Add(&#34;marks&#34;); dt.Rows.Add(&#34;it&#34;, &#34;abc&#34;, &#34;80&#34;); dt.Rows.Add(&#34;cs&#34;, &#34;xyz&#34;, &#34;67&#34;); dt.Rows.Add(&#34;mec&#34;, &#34;abc&#34;, &#34;76&#34;); dt.Rows.Add(&#34;ece&#34;, &#34;xyz&#34;, &#34;73&#34;); dt.Rows.Add(&#34;it&#34;, &#34;ab&#34;, &#34;85&#34;); DataTable dt2 = new DataTable(); dt2.Columns.Add(&#34;Department&#34;); dt2.Columns.Add(&#34;name&#34;); dt2.Columns.Add(&#34;marks&#34;); dt2.Rows.Add(&#34;it&#34;, &#34;abc&#34;, &#34;80&#34;); dt2.Rows.Add(&#34;cs&#34;, &#34;xyz&#34;, &#34;50&#34;); dt2.Rows.Add(&#34;mec&#34;, &#34;abc&#34;, &#34;76&#34;); dt2.Rows.Add(&#34;eee&#34;, &#34;abc&#34;, &#34;40&#34;); //Multiple Condition var dt1result = dt.AsEnumerable(); var dt2result = dt2.AsEnumerable(); var result = (from dt1Row in dt1result from dt2Row in dt2result where dt1Row[&#34;name&#34;] == dt2Row[&#34;name&#34;] &amp;&amp; dt1Row[&#34;Department&#34;] == dt2Row[&#34;Department&#34;] &amp;&amp; Convert.ToInt32(dt1Row[&#34;marks&#34;]) == Convert.ToInt32(dt2Row[&#34;marks&#34;]) select new { name = dt1Row.Field&lt;string&gt;(&#34;name&#34;), marks = dt1Row.Field&lt;string&gt;(&#34;marks&#34;), department = dt2Row.Field&lt;string&gt;(&#34;Department&#34;) }); GridView1.DataSource = dt; GridView1.DataBind(); GridView2.DataSource = dt2; GridView2.DataBind(); GridView3.DataSource = result; GridView3.DataBind(); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim dt As DataTable = New DataTable() dt.Columns.Add(&#34;Department&#34;) dt.Columns.Add(&#34;name&#34;) dt.Columns.Add(&#34;marks&#34;) dt.Rows.Add(&#34;it&#34;, &#34;abc&#34;, &#34;80&#34;) dt.Rows.Add(&#34;cs&#34;, &#34;xyz&#34;, &#34;67&#34;) dt.Rows.Add(&#34;mec&#34;, &#34;abc&#34;, &#34;76&#34;) dt.Rows.Add(&#34;ece&#34;, &#34;xyz&#34;, &#34;73&#34;) dt.Rows.Add(&#34;it&#34;, &#34;ab&#34;, &#34;85&#34;) Dim dt2 As DataTable = New DataTable() dt2.Columns.Add(&#34;Department&#34;) dt2.Columns.Add(&#34;name&#34;) dt2.Columns.Add(&#34;marks&#34;) dt2.Rows.Add(&#34;it&#34;, &#34;abc&#34;, &#34;80&#34;) dt2.Rows.Add(&#34;cs&#34;, &#34;xyz&#34;, &#34;50&#34;) dt2.Rows.Add(&#34;mec&#34;, &#34;abc&#34;, &#34;76&#34;) dt2.Rows.Add(&#34;eee&#34;, &#34;abc&#34;, &#34;40&#34;) Dim dt1result = dt.AsEnumerable() Dim dt2result = dt2.AsEnumerable() Dim result = (From dt1Row In dt1result From dt2Row In dt2result Where dt1Row(&#34;name&#34;) = dt2Row(&#34;name&#34;) AndAlso dt1Row(&#34;Department&#34;) = dt2Row(&#34;Department&#34;) AndAlso Convert.ToInt32(dt1Row(&#34;marks&#34;)) = Convert.ToInt32(dt2Row(&#34;marks&#34;)) Select New With {Key .name = dt1Row.Field(Of String)(&#34;name&#34;), Key .marks = dt1Row.Field(Of String)(&#34;marks&#34;), Key .department = dt2Row.Field(Of String)(&#34;Department&#34;)}) GridView1.DataSource = dt GridView1.DataBind() GridView2.DataSource = dt2 GridView2.DataBind() GridView3.DataSource = result GridView3.DataBind() End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/BMoe2eK.jpg" alt="" width="463" height="399" /></p>https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/Mon, 03 Dec 2018 03:39:59 GMTAdd multiple Where condition in Linq query using C# and VB.Net<p>thanks for reply, but in my example there is two datatable. comparing one with second with some keys.</p>https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/Mon, 03 Dec 2018 03:48:15 GMTAdd multiple Where condition in Linq query using C# and VB.Net<p>Hey <a class="username" rel="yogesjoshi"> yogesjoshi</a>,</p> <p>This is an example how to use multiple column in where condition.</p> <p>So please refer provided code and&nbsp;implement it in your code.</p>https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/Mon, 03 Dec 2018 04:39:21 GMTAdd multiple Where condition in Linq query using C# and VB.Net<blockquote><cite>pandeyism says:</cite> <p>Hey <a class="username" rel="yogesjoshi"> yogesjoshi</a>,</p> <p>This is an example how to use multiple column in where condition.</p> <p>So please refer provided code and&nbsp;implement it in your code.</p> </blockquote> <p>&nbsp;i have already got solution with one table with multiple condition. i wants to know my problem solution. is there any other way to do this.</p> <p>thanks in advance.</p>https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/Mon, 03 Dec 2018 22:16:18 GMTAdd multiple Where condition in Linq query using C# and VB.Net<p>Hey <a class="username" rel="yogesjoshi"> yogesjoshi</a>,</p> <p>Please refer below link. Previoues reply has been updated.</p> <p><a href="https://www.aspforums.net/Threads/320677/Linq-to-add-multipe-condition-with-select-and-where/Replies/2#Replies">https://www.aspforums.net/Threads/320677/Linq-to-add-multipe-condition-with-select-and-where/Replies/2#Replies</a></p>https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/https://www.aspforums.net:443/Threads/320677/Add-multiple-Where-condition-in-Linq-query-using-C-and-VBNet/Tue, 04 Dec 2018 03:09:27 GMT