Use the Overloaded Fill method of the SqlDataAdapter/OleDbDataAdapter Code snippet
(Windows Application)
Take a DataGridView. Key in the code in Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication3
{
public partial class Form4 : Form
{
SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=1234;database=northwind");
SqlDataAdapter da;
DataSet ds = new DataSet();
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
da = new SqlDataAdapter("select * from products", cn);
da.Fill(ds, 1, 5, "demo");
dataGridView1.DataSource = ds.Tables["demo"];
//it will display records from 2 to 6
//1: index number of the record(it starts from 0)
//5:number of records from the index position
}
}
}