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

Explain the advantage of ADO.Net?

746


What are the 3 major types of connection objects in ado.net?

756


What is full form of ado?

717


Does executenonquery return a value?

718


Define ado.net?

804


What are the advantage of ado.net?

734


What is data access pattern?

670


Explain the difference between data reader and data set?

685


Can you explain how to enable and disable connection pooling?

725


What is sqldatasource?

709


What is ole data type?

704


How do you connect to sql server database without using sqlclient?

778


Explain the DataAdapter.Update() and DataSetAcceptChanges() methods.

743


Give few examples of datareader that is used in different dataproviders.

742


how to create a quiz software using 4 options to answer and how to check with answers in the database and award marks....

3992