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.Compare Database column with string array using C# and VB.Net in ASP.Net<p>Hi&nbsp;Vikash21,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">string[] myArray = new string[] { &#34;Aa&#34;, &#34;Bb&#34;, &#34;Cc&#34; }; System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.AddRange(new System.Data.DataColumn[] { new System.Data.DataColumn(&#34;Name&#34;, typeof(string)), new System.Data.DataColumn(&#34;Age&#34;, typeof(int)), new System.Data.DataColumn(&#34;Title&#34;,typeof(string)) }); dt.Rows.Add(&#34;Aa&#34;, 31, &#34;Consultant&#34;); dt.Rows.Add(&#34;Bb&#34;, 32, &#34;Consultant&#34;); dt.Rows.Add(&#34;Cc&#34;, 33, &#34;Sr Consultant&#34;); dt.Rows.Add(&#34;Dd&#34;, 34, &#34;Manager&#34;); System.Data.DataTable dtFinal = dt.Clone(); for (int i = 0; i &lt; dt.Rows.Count; i++) { if (myArray.Contains(dt.Rows[i][&#34;Name&#34;].ToString())) { dtFinal.ImportRow(dt.Rows[i]); } } GridView gvDetails = new GridView(); gvDetails.DataSource = dtFinal; gvDetails.DataBind(); form1.Controls.Add(gvDetails);</pre> <p><span style="text-decoration: underline;"><strong>VB.Net</strong></span></p> <pre class="brush: vb">Dim myArray As String() = New String() {&#34;Aa&#34;, &#34;Bb&#34;, &#34;Cc&#34;} Dim dt As Data.DataTable = New Data.DataTable() dt.Columns.AddRange(New Data.DataColumn() { New Data.DataColumn(&#34;Name&#34;, GetType(String)), New Data.DataColumn(&#34;Age&#34;, GetType(Integer)), New Data.DataColumn(&#34;Title&#34;, GetType(String))}) dt.Rows.Add(&#34;Aa&#34;, 31, &#34;Consultant&#34;) dt.Rows.Add(&#34;Bb&#34;, 32, &#34;Consultant&#34;) dt.Rows.Add(&#34;Cc&#34;, 33, &#34;Sr Consultant&#34;) dt.Rows.Add(&#34;Dd&#34;, 34, &#34;Manager&#34;) Dim dtFinal As Data.DataTable = dt.Clone() For i As Integer = 0 To dt.Rows.Count - 1 If myArray.Contains(dt.Rows(i)(&#34;Name&#34;).ToString()) Then dtFinal.ImportRow(dt.Rows(i)) End If Next Dim gvDetails As GridView = New GridView() gvDetails.DataSource = dtFinal gvDetails.DataBind() form1.Controls.Add(gvDetails)</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <table border="1" rules="all" cellspacing="0"> <tbody> <tr><th scope="col">Name</th><th scope="col">Age</th><th scope="col">Title</th></tr> <tr> <td>Aa</td> <td>31</td> <td>Consultant</td> </tr> <tr> <td>Bb</td> <td>32</td> <td>Consultant</td> </tr> <tr> <td>Cc</td> <td>33</td> <td>Sr Consultant</td> </tr> </tbody> </table>https://www.aspforums.net:443/Threads/659966/Compare-Database-column-with-string-array-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/659966/Compare-Database-column-with-string-array-using-C-and-VBNet-in-ASPNet/Fri, 26 Jul 2019 01:50:19 GMT