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.Populate Windows Form DataGridView from specific range of rows using C# and VB.Net<p>Hi <a class="username" rel="satabeach"> satabeach</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>Database</strong></span></p> <p>For this sample I have used of NorthWind database that you can download using the link given below.</p> <p><a href="https://www.aspsnippets.com/Articles/Install-the-Northwind-and-Pubs-Sample-Databases-in-SQL-Server-Express.aspx" target="_blank">Download Northwind Database</a></p> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data.SqlClient; </pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">private void Form1_Load(object sender, EventArgs e) { string constr = @&#34;Server=.\SQL2005;DataBase=Northwind;UID=user;PWD=pass&#34;; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT City, Country FROM Customers&#34;, con)) { using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DataTable dt = new DataTable(); da.Fill(dt); var rows = dt.Select().Skip(5).Take(10); DataRow[] dr = rows.ToArray(); DataTable dt1 = dr.CopyToDataTable(); dataGridView1.DataSource = dt1; } } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim constr As String = &#34;Server=.\SQL2005;DataBase=Northwind;UID=user;PWD=pass&#34; Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand(&#34;SELECT City, Country FROM Customers&#34;, con) Using da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim dt As DataTable = New DataTable() da.Fill(dt) Dim rows = dt.Select().Skip(5).Take(10) Dim dr As DataRow() = rows.ToArray() Dim dt1 As DataTable = dr.CopyToDataTable() dataGridView1.DataSource = dt1 End Using End Using End Using End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><span style="text-decoration: underline;"><strong><img src="https://imgur.com/rWThBcj.jpg" alt="" width="305" height="275" /></strong></span></p>https://www.aspforums.net:443/Threads/170588/Populate-Windows-Form-DataGridView-from-specific-range-of-rows-using-C-and-VBNet/https://www.aspforums.net:443/Threads/170588/Populate-Windows-Form-DataGridView-from-specific-range-of-rows-using-C-and-VBNet/Mon, 12 Nov 2018 02:22:44 GMT