Showing posts with label sum. Show all posts
Showing posts with label sum. Show all posts

Saturday, March 24, 2012

Sum Calculation Query

Hi,

Within an access database I want to be able to add some values and calculate the sum of these values. Using asp.net 1.1. with vb.net, how would I achieve this ?

Presumably I could perform a look up within the databse and then use sind kind of function to add the required values ? Can anyone offer any suggestions or point to any useful online examples ?

Thanks,

reather than use asp.net to add up your columns why not use your datasource to do this.

like an sql query:

select sum(amount)

From TBLIntegerHolder

where amount > 0

something like that


Write a query within access to do the necessary data manipulation and the read the result.

Hi,

Use sum() function in the sql query.


Thanks all

Sum a Datagrid row?

Hello all,

I have a datagrid that returns sales of items by month from an Oracle
table using a datareader like so:

Item |Jan |Feb | ... |Dec
itm1 |10 |5 | ... |6
itm2 |7 |2 | ... |8

I want to add a column to the end of the datagrid that would sum the
row:
Item |Jan |Feb | ... |Dec |Total
itm1 |10 |5 | ... |6 |21
itm2 |7 |2 | ... |8 |17

I would think that this would be easy to do, but I can only find
articles that explain how sum a column into a footer. Could someone
point me in the right direction? I've only been programming in
asp.net for about four months now, so the help is appreciated.Use the binding event of the Grid view (or DataGrid in .NET 1.1) and sum the
columsn there. Go ahead and explicitly add this column to the DataSet in the
designer (and the rest of the columns if you are wise). In the binding event
grab the current binding row and then access the columns in question.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
"ClevelandSteve" <syahnert@.hotmail.comwrote in message
news:1155759519.915735.90550@.i42g2000cwa.googlegro ups.com...

Quote:

Originally Posted by

Hello all,
>
I have a datagrid that returns sales of items by month from an Oracle
table using a datareader like so:
>
Item |Jan |Feb | ... |Dec
itm1 |10 |5 | ... |6
itm2 |7 |2 | ... |8
>
I want to add a column to the end of the datagrid that would sum the
row:
Item |Jan |Feb | ... |Dec |Total
itm1 |10 |5 | ... |6 |21
itm2 |7 |2 | ... |8 |17
>
I would think that this would be easy to do, but I can only find
articles that explain how sum a column into a footer. Could someone
point me in the right direction? I've only been programming in
asp.net for about four months now, so the help is appreciated.
>


I got it working now. Thank you for the tip.

SUM LIST By Month and Year - HELP PLEASE!


{

I need to loop through a list, find the amounts for the same month and year. How can I find all the values for a month and year, add them and set them to an new variable?

Below is the codle of the list I am using to Loop and its results, thank you for your help!

Response.Write("<table border=1 class=tdRowCenter width=300>");foreach(GenericList AmonuntsLoopin MyList)

Response.Write(<SPAN class=st>"&lt;tr><td>Month</td><td>"</SPAN> + AmonuntsLoop.Month + <SPAN class=st>"&lt;/td><td>Year</td><td>"</SPAN> + AmonuntsLoop.Year + <SPAN class=st>"&lt;/td><td>Amount</td><td>"</SPAN> + AmonuntsLoop.MonthlyAmount + <SPAN class=st>"&lt;/td></tr>"</SPAN>);
}

Response.Write(<SPAN class=st>"&lt;/table>"</SPAN>);

 

output for testing only

Month1Year2006Amount17722.94Month2Year2006Amount18093.19Month3Year2006Amount18157.50Month4Year2006Amount16371.90Month5Year2006Amount17338.10Month6Year2006Amount17345.06Month7Year2006Amount18921.64Month8Year2006Amount18836.68Month9Year2006Amount20741.74Month10Year2006Amount17362.87Month11Year2006Amount15228.85Month1Year2005Amount17138.79Month2Year2005Amount16802.48Month3Year2005Amount18000.43Month4Year2005Amount16040.48Month5Year2005Amount9755.48Month6Year2005Amount19097.73Month7Year2005Amount18267.06Month8Year2005Amount18832.51Month9Year2005Amount20163.64Month10Year2005Amount16937.13Month11Year2005Amount16114.66Month12Year2005Amount18602.90Month1Year2006Amount22209.40Month2Year2006Amount20738.59Month3Year2006Amount18499.77Month4Year2006Amount21951.75Month5Year2006Amount19402.30Month6Year2006Amount21563.31Month7Year2006Amount22855.29Month8Year2006Amount26106.09Month9Year2006Amount22854.72Month10Year2006Amount25766.62Month11Year2006Amount19548.18Month1Year2005Amount20765.76Month2Year2005Amount20233.43Month3Year2005Amount19161.78Month4Year2005Amount20528.22Month5Year2005Amount18855.83Month6Year2005Amount20129.81Month7Year2005Amount21382.53Month8Year2005Amount25826.96Month9Year2005Amount22054.56Month10Year2005Amount25469.49Month11Year2005Amount22037.02Month12Year2005Amount21151.57

For example I need to add 1/2005 entries and end up with39,932.34

This is pretty crude, but you could do something like this...

1string curMonth ="";2string curYear ="";34double totalMonth = 0;5double totalYear = 0;67foreach(GenericList AmountsLoopin MyList)8{9// suggestion on writing your html line10 Response.Write(String.Format("<tr><td>{0}</td></tr>", AmountsLoop.Month)11 totalMonth += AmountsLoop.MonthlyAmount;12 totalYear += AmountsLoop.MonthlyAmount;1314if (AmonuntsLoop.Month != curMonth)15 {16 Response.Write(String.Format("{0}'s total is {1:c}", curMonth, totalMonth));17 curMonth = AmonuntsLoop.Month;18 totalMonth = 0;19 }2021if (AmonuntsLoop.Year != curYear)22 {23 Response.Write(String.Format("{0}'s total is {1:c}", curYear, totalYear));24 curYear = AmonuntsLoop.Year;25 totalYear = 0;26 }27}28

Thanks, but is there another non crude way using Generics? I have the data in a Generic List

sum of column in footer

Is there a way to sum all the columns values in a gridview and show it in
the footer of that column? anyone try this before? thanks!Hi,
you can do it by handling RowRataBound event of the GridView. Calculate sums
in it (as it's repeated for every row) and when GridViewRow's RowType is
Footer, place the sum value into it (for example by using a TemplateField
having Label in footer to which you set the sum, as it's Text value)
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Smokey Grindle" <nospamhere@.dontspam.net> wrote in message
news:efKT5aInGHA.4352@.TK2MSFTNGP02.phx.gbl...
> Is there a way to sum all the columns values in a gridview and show it in
> the footer of that column? anyone try this before? thanks!
>
hello smokey
here's a working code example. hope it helps
http://authors.aspalliance.com/aspx...wdatabound.aspx
hello smokey
here's a working code example. hope it helps
http://authors.aspalliance.com/aspx...wdatabound.aspx
thanks everyone!
"ReyN" <rvnunez@.yahoo.com> wrote in message
news:1151736818.909778.118790@.m79g2000cwm.googlegroups.com...
> hello smokey
> here's a working code example. hope it helps
> http://authors.aspalliance.com/aspx...wdatabound.aspx
>

sum of column in footer

Is there a way to sum all the columns values in a gridview and show it in
the footer of that column? anyone try this before? thanks!Hi,

you can do it by handling RowRataBound event of the GridView. Calculate sums
in it (as it's repeated for every row) and when GridViewRow's RowType is
Footer, place the sum value into it (for example by using a TemplateField
having Label in footer to which you set the sum, as it's Text value)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Smokey Grindle" <nospamhere@.dontspam.net> wrote in message
news:efKT5aInGHA.4352@.TK2MSFTNGP02.phx.gbl...
> Is there a way to sum all the columns values in a gridview and show it in
> the footer of that column? anyone try this before? thanks!
>
hello smokey

here's a working code example. hope it helps

http://authors.aspalliance.com/aspx...wdatabound.aspx
hello smokey

here's a working code example. hope it helps

http://authors.aspalliance.com/aspx...wdatabound.aspx
thanks everyone!

"ReyN" <rvnunez@.yahoo.com> wrote in message
news:1151736818.909778.118790@.m79g2000cwm.googlegr oups.com...
>
> hello smokey
>
> here's a working code example. hope it helps
>
> http://authors.aspalliance.com/aspx...wdatabound.aspx
>

Sum on datagrid

How can I get the sum of an itemcolumn in a datagrid? I know I can use a seperate query to get it, but I would like to know how I can get the product listing and Sum using the same query

ThanksHi there,

Try this linkDisplaying Sum Total in a DataGrid

Hope this helps

Sum of XML data

I am reading an XML file and writing its contents to a Repeater control using the following code:

Dim dstTS As DataSet

dstTS = New DataSet()
dstTS.ReadXml( MapPath( "cw052004.xml" ) )

rptTS.DataSource = dstTS
rptTS.DataBind()

It works fine. However, I would also like to calculate the sum of a the "item_cost" from each node in the XML file and place it in a variable.

Can anybody suggest the best way to go about this?do some searching for examples on the itemdatabound event. this is fired everytime an item is bound and you can use this to sum up your grids and such.
Awesome, thanks!

Sum result in Label field

I summed a column of numbers and would like to put them in a Label field to display the result. I understand the conversion for number to string, I don't understand how to that value, that has been summed, to do it.

thanks
grady

int x = 7;
int y = 7;
int z = x + y;

LabelID.Text = z.ToString();

Is that what you're looking for?

HTH,
Ryan


Actually I have summed a column called TFsum and I was trying to display that and it say it was undeclared.

Here is the SQL:
SELECT SUM(filesfailed) AS TFsum
FROM accmonreport
WHERE oa='ddlOA'
HAVING SUM(filesfailed)=0

ddlOA is a dropdown list in the first view on the page. I'm just to get the variable TFsum to do some calculations.

thanks
grady


Could you post the relevent code?

Ryan


All I'm trying now is get the TFsum value into the lblcompliant label.

thanks
grady

Imports System.Data
Imports System.Data.OleDB
Imports System.Data.OleDb.OleDbDataReader

Partial Class reports_508report
Inherits System.Web.UI.Page

Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

If (Page.IsValid) Then

Dim ddlOA As String = ddloalist.SelectedValue

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\accmon\database\accmon.mdb" & ";"
Dim MySQL As String = "SELECT SUM(filesfailed)AS TFsum FROM accmonreport WHERE oa='ddlOA' HAVING filesfailed=0"
Dim MyConn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(MySQL, MyConn)
MyConn.Open()
cmd.ExecuteReader()
MyConn.Close()

lblCompliant.Text = " "

OAReport.SetActiveView(Result)
End If

End Sub

End Class


You need to make a couple of changes.

If (Page.IsValid) Then

Dim ddlOA As String = ddloalist.SelectedValue

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\accmon\database\accmon.mdb" & ";"
Dim MySQL As String = "SELECT SUM(filesfailed)AS TFsum FROM accmonreport WHERE oa='" & ddlOA & "' HAVING filesfailed=0"
Dim reader As OleDbDataReader
Dim MyConn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(MySQL, MyConn)
MyConn.Open()
reader =cmd.ExecuteReader()

While reader.Read()
lblCompliant.Text = reader("TFsum")
End While

reader.Close()
MyConn.Close()

OAReport.SetActiveView(Result)
End If

HTH,
Ryan


Thanks, I really appreciate your time and knowledge. If you don't mind, I have one more question. In Coldfusion there is a function that gives me a recordcount after every query. How do you implement something like that in .Net?

thanks
grady