i have a table wchich has two columns named as 'sl.no.' and 'total'
and it has 5 values in rows like
sl.no total
1 3
2 5
3 2
4 3
5 4
now i want to add only the rows starts from sl.no -2 to sl.no -4
i an using this code but its not working please let me out
object sumobject
for (p = 2; p <= 4; p++)
{
DataTable dt;
dt = dsu.Tables[username.Text];
sumobject = dt.Compute("sum(total)", "sl.no=" + p + "");
}
reasoning0.Text = sumobject.ToString();

Tirthak Shah196 reputationPosted Dec 25, 2013, 3:21 AM EST
"select sum(total) from test where [sl.no] between 2 and 4"
And Execute it it will return a column (Total).
Thanks And Regards,
Tirthak Shah
Abhay ShankerRank #375 · 6.7K reputationPosted Dec 25, 2013, 3:28 AM EST
get datatable as below query
select * from tablename orderby sl.no
int sum=0;
for(i=0;i<3;i++)
sum=sum+convert.toint32(dt.rows[i+1]["total"])