If a dataset contains 100 rows, how to fetch rows between 10
and 20 only ?

Answer Posted / abhishek_gp3

Use Overloaded Fill() function of SqlDataAdapter Class of System.Data.SqlClient namespace.

Fill(1,2);
1- Dataset object
2- Table name

Fill(1,2,3,4);
1- Dataset Object
2- Starting Rec.
3- End Rec.
4- Table Name
--
Sample prog:
------
using System;
using System.Windows;
using System.Data;
using System.Data.SqlDataAdapter;

Class FetchRec
{
SqlConnection Con;
SqlDataAdapter Adap;
Dataset ds;

Public FetchRec()
{
Con = new SqlConnection("initial catalog=master;integrated security=yes");
Con.Open();

Adap= new SqlDataAdapter("Select ID, Name from Employee where ID > 110");

ds= new Dataset();
}//constructor end

try{
ds = Adap.Fill(ds, 10, 20, "Employee");

int rcount=ds.Tables["Employee"].Rows.Count;

for(int i=0; i < rcount ; i++)
{
Console.Writeline(ds.Tables["Employee"].Rows[i][0] + ds.Tables["Employee"].Rows[i][1]);
}

con.close();
} //try end
catch(SqlException exp)
{
MessageBox.Show(exp.Message);
}

}//class end

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Define ado.net?

816


Which namespaces are used for data access?

876


Does entity framework use ado.net?

740


What is ado code?

730


What is the difference between linq and ado.net?

748


What are the different execute methods of Ado.Net?

767


What is datasource in ado.net?

839


How would you connect to a database by using .NET?

726


What is ado.net explain with diagram?

732


What are the steps you will take to improve performance? Will you use dataset or datareader?

762


What is serialization and de-serialization in .net?

722


What are the different methods available under the sqlcommand class to access the data?

815


how Sequence to connect and retrieve data from database using dataset?

981


Which is faster sqldataadapter and sqldatareader?

720


differences between ADO and ADO.NET

821