locked
how to sum multiple sql statements in C#? RRS feed

  • Question

  • User2113851930 posted

    hi

    I have a problem

    I want to have a total sum of the detail sum

    one.SelectCommand = "SELECT SUM as ....
    two.SelectCommand = "SELECT SUM as ....

    I want label.text =  (one + two)

    But how can I put number two into this statement ?

    DataView dvSql = (DataView)one.Select(DataSourceSelectArguments.Empty);

    foreach (DataRowView drvSql in dvSql)
            {

                Label.Text = Convert.ToDecimal(drvSql["one"]).ToString("F2");

            }

           


    Tuesday, December 4, 2012 5:54 PM

All replies

  • User-40287846 posted

    int i =0;

    DataView dvSql = (DataView)one.Select(DataSourceSelectArguments.Empty); foreach (DataRowView drvSql in dvSql)         {

               i = i + Convert.ToDecimal(drvSql["one"]).ToString("F2");

     i =  i +  Convert.ToDecimal(drvSql["two"]).ToString("F2");

            }

     Label.Text = i.ToString()

    Tuesday, December 4, 2012 6:47 PM
  • User2113851930 posted

    this way

     

    One.SelectCommand="Select sum() as....................";

    DataView dvSql = (DataView)one.Select(DataSourceSelectArguments.Empty);
    foreach (DataRowView drvSql in dvSql)

    {

     int i =0;
     i = i + Convert.ToDecimal(drvSql["one"]);
     Label.Text = i.ToString()

    }

    Tuesday, December 11, 2012 11:33 AM
  • User2113851930 posted

    why can I not this here ???

    I get this error for the DataView dvSql2: Embedded statement cannot be a declaration og labeled statement

    My code

    One.SelectCommand="Select sum() as....................";
    Two.Selectcommand="Select sum() as....................";

    DataView dvSql = (DataView)one.Select(DataSourceSelectArguments.Empty); foreach (DataRowView drvSql in dvSql)

    DataView dvSql2 = (DataView)two.Select(DataSourceSelectArguments.Empty); foreach(DataRowView drvSql2 in dvSql2)

    {

    int i = 0;

    i = i + Convert.ToDecimal(drvSql["column"]);

    i =  i +  Convert.ToDecimal(drvSql2["column"]);

    Label.Text = i.ToString()

    }

    Tuesday, December 11, 2012 11:55 AM