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
What are the key features of ado.net?
What is the difference between dataset and datatable?
What is the difference between the clone() and copy() methods of the dataset class?
What is a sqldataadapter?
What is serialization and de-serialization in .net? How can we serialize the dataset object?
How to generate a single aggregate?
Which keyword is used to accept variable number of parameters?
Difference between sqlcommand and sqlcommandbuilder?
What is the default provider in ado.net?
What is the use of SqlCommand object?
What is ado.net in mvc?
What is namespace in ado.net?
What is ole access?
What are the major challenges in accessing data from a database?
Which is better entity framework or ado.net?