if a dataset has about 77 records, how can we display a specific range of records(ex record number 2 to 6)

Posted by Ddd under Windows Forms category on | Points: 40 | Views : 2284
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()

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


Comments or Responses

Login to post response