Add the entire table of the database and show it with the total

0

I would like to add all the data stored in my price table, this table price (money) saves the price of some pizzas (it is a program of sale of pizzas) each pizza has a price of € 10, I would like to add it and show the price end in a MessageBox.show ().

For now I have tried to do so

SqlConnection conexion = new SqlConnection("server=JAUMEVIVES\SQLEXPRESS; database=Proyecto; Integrated Security = SSPI");
         SqlCommand comandosql = new SqlCommand();
         conexion.Open();
         comandosql.Connection = conexion;
         comandosql.CommandText = "SELECT SUM(Precio) FROM Pizzas";
        SqlDataReader midatareader = comandosql.ExecuteReader();
        string precio;
        precio = midatareader["Precio"].ToString();

        MessageBox.Show("Su precio total es"+precio);

Thank you very much in advance, if there is anything you need to ask, I am learning alone and it costs me a little, do not be hard on me:)

    
asked by El Barto 04.06.2018 в 11:45
source

0 answers