If a dataset contains 100 rows, how to fetch rows between 5 and 15

Posted by Deepak under Sql Server on 2/5/2009 | Views : 5303 | Status : [Member] | Replies : 6
If a dataset contains 100 rows, how to fetch rows between 5 and 15 only?




Responses

Posted by: Learner on: 2/5/2009 [Member] Starter

Up
0
Down
Use DataView.RowFilter

For more Info:
http://en.csharp-online.net/DataViews_and_Data_Binding%E2%80%94Filter_operators

Deepak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 2/5/2009 [Member] Starter

Up
0
Down
Hi

SqlDataAdapter da=new SqlDataAdapter("select * from emp",conn);
DataSet ds=new DataSet();
da.Fill(ds,"emp");
int rowcount=ds.Tables["emp"].Rows.Count;
if(rowcount>=15)
{
for(int i=5;i>=15;i++)
{
textbox1.Text=Convert.ToString(ds.Tables["emp"].Rows[i]["columnname1"].ToString());
textbox2.Text=Convert.ToString(ds.Tables["emp"].Rows[i]["columnname2"].ToString());
}
}
else
{
Respone.write("Table rows are less than 15");
}
}

Syed Shakeer Hussain

Deepak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learner on: 2/5/2009 [Member] Starter

Up
0
Down
Another Way is

DataAdapter.Fill(Dataset,startrecord as Integer, maxrecord as integer,tablename)

Specify the startrecord = 5 and maxrecord =15

Deepak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Deepak on: 2/5/2009 [Member] Starter

Up
0
Down

Hi ...

You never used "i" anywhere?

May I know in details?

Deepak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 2/5/2009 [Member] Starter

Up
0
Down
Hi

SqlDataAdapter da=new SqlDataAdapter("select * from emp",conn);
DataSet ds=new DataSet();
da.Fill(ds,"emp");
int rowcount=ds.Tables["emp"].Rows.Count;
if(rowcount>=15)
{
for(int i=5;i>=15;i++)
{
textbox1.Text=Convert.ToString(ds.Tables["emp"].Rows[i]["columnname1"].ToString());
textbox2.Text=Convert.ToString(ds.Tables["emp"].Rows[i]["columnname2"].ToString());
}
}
else
{
Respone.write("Table rows are less than 15");
}
}

Syed Shakeer Hussain

Deepak, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 2/5/2009 [Member] Starter

Up
0
Down
Hi

SqlDataAdapter da=new SqlDataAdapter("select * from emp",conn);
DataSet ds=new DataSet();
da.Fill(ds,"emp");
int rowcount=ds.Tables["emp"].Rows.Count;
if(rowcount>=15)
{
for(int i=5;i>=15;i++)
{
textbox1.Text=Convert.ToString(ds.Tables["emp"].Rows[i]["columnname1"].ToString());
textbox2.Text=Convert.ToString(ds.Tables["emp"].Rows[i]["columnname2"].ToString());
}
}
else
{
Respone.write("Table rows are less than 15");
}
}

Syed Shakeer Hussain

Deepak, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response