Sum of a Sqldatasource result

Asked

Viewed 159 times

0

I am developing a reporting system to control calls and need to take the result of a query and make a sum that brings me the total number of calls per sector of a certain number.

I’m using Stored Procedure with Mysql database and the development is in ASP.Net. I’m trying this way.

I declared the variables receiving zero:

Double TotalLigacoes, TotalSetor, TotalSac, TotalProjetos, TotalTI, TotalADMINISTRATIVO, TotalComercial, TotalDiretoria, TotalRecepcao, TotalOutros = 0;

protected void GvSetor_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.Cells.[0].text == "ADMINISTRATIVO")
    {
        TotalADM = TotalADM + Convert.ToDouble( TotalADM + e.Row.Cells[1].Text);
    }
}

I have to do something like a looping to sum the minutes of `Sqldatasource (Separated by sector) and sum in one variable to display in the other grid.

  • 1

    But what’s your problem? There was some mistake?

  • TotalADM was not declared. Would TotalADMINISTRATIVO?

  • Sorry. I changed but when I posted, I posted wrong.

  • The problem is that I don’t know how to fix this and I’m giving an error. Indetifier expected. How do I put Print here? Thanks.

  • @fabricio_wm http://answall.com/editing-help

  • It had a dot before the brackets in the if. But it’s returning zero.

Show 1 more comment

1 answer

2

TotalADM = TotalADM + Convert.ToDouble( TotalADM + e.Row.Cells[1].Text);

With this you are adding Totaladm twice. Do so:

TotalADM += Convert.ToDouble(e.Row.Cells[1].Text);

  • So I’ll just add up the minutes of the administrative sector? ?

  • protected void Gvrelatorio_rowdatabound(Object Sender, Gridviewroweventargs e) { if(e.Row.Cells[4].Text == "ADMINISTRATIVE") { Totaladm += Convert.Todouble(e.Row.Cells[5].Text); } } protected void Gvsetor_rowdatabound(Object Sender, Gridviewroweventargs and) { if (e.Row.Cells[0].Text == "ADMINISTRATIVE") { e.Row.Cells[1]. Text = Convert.Tostring(Totaladm) + " Min."; } }

  • No man, there was an error in the way you were doing the count (duplicate sum). I’m seeing now that your problem is another... Try to be more precise, if possible post an error print or stack trace!

  • 1

    Thank you. Solved otherwise as link. http://answall.com/questions/6752/resultado-diferente-entre-select-apos-aplica-o-sum-e-o-grop-by/6760?noredirect=1#comment11367_6760

Browser other questions tagged

You are not signed in. Login or sign up in order to post.