SiteMap  | About    

Display Selected range of records

The DataAdapter serves as a bridge between a DataSet and a data source for retrieving and saving data. When an instance of DataAdapter is created, the read or write properties are set to initial values. A DataSet is made up of a collection of tables, relationships, and constraints. In ADO.NET, DataTable objects are used to represent the tables in a DataSet. The DataSet is designed to be used in a disconnected mode.

  Dim ds As New DataSet

In some situations we need to retrieve data only specific range of rows. In this situations we can fill the Dataset from DataAdapter only that specific range of rows. The following piece of code shows how to fill specific range of rows from DataAdapter to Dataset.

  DataAdapter.Fill(Dataset, 5, 3, "tablename")

The above code will fill the Dataset starting from 5th row and no of rows 3.

5 is the starting row no

3 is no of rows we want to fill.

imports System.IO
Imports System.Data.SqlClient
Public Class Form1
	Dim cnn As SqlConnection
	Dim connectionString As String
	Dim sqlAdp As SqlDataAdapter
	Dim ds As New DataSet

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim i As Integer
		connectionString = "Data Source=servername; Initial Catalog=databasename; User ID=userid; Password=password"
		cnn = New SqlConnection(connectionString)
		sqlAdp = New SqlDataAdapter("select * from users", cnn)

		sqlAdp.Fill(ds, 5, 3, "users")

		'5 is starting row no.
		'3 is no of rows to retrieve

		For i = 0 To ds.Tables(0).Rows.Count - 1

	End Sub
End Class (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.