Beispiel #1
0
        public double Sumar_Valores_de_Campos(string sqlsum)
        {
            double         res = 0;
            OdbcDataReader dr  = null;

            if (conexion.State == ConnectionState.Open)
            {
                conexion.Close();
            }
            conexion.Open();
            try
            {
                dr = new OdbcCommand(sqlsum, conexion).ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    if (dr.IsDBNull(0))
                    {
                        res = 0;
                    }
                    else
                    {
                        res = Convert.ToDouble(dr.GetValue(0));
                    }
                }
                //if (Convert.ToDouble(new OdbcCommand(sqlsum, conexion).ExecuteScalar()) >= 0)
                //{
                //    res = Convert.ToDouble(new OdbcCommand(sqlsum, conexion).ExecuteScalar());
                //}
                //else
                //{
                //    res = 0;
                //}
            }
            catch (Exception ex)
            {
                res = 0;
                MessageBox.Show("Error al momento de realizar la suma de valores de la Data Base: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                dr.Close();
            }
            return(res);
        }