Hi,
A DataSet object contains a collection of DataTable objects. A DataTable object is representing a database table with rows and columns which are the most important things of a Datatable object.
There is no Sum() function to do totals directly on a given column but you could write it in few statements by iterating all rows of the DataTable object.
Let be dt a DataTable object with a column named Amount and a type of data Integer:
int sum =0;
foreach (DataRow dr in dt.Rows)
{
sum+=(int)dr["Amount"];
}
If the Amount column has a type of System.string but there are in fact numbers , then:
int sum =0;
foreach (DataRow dr in dt.Rows)
{
sum+=System.Convert.ToInt32(dr["Amount"].ToString());
}
-obislavu-
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.