In computed tomography (CT), the polychromatic characteristics of x-ray photons, which are emitted from a source, interact with materials and are absorbed by a detector, may lead to beam-hardening effect in signal detection and image formation, especially in situations where materials of high attenuation (e.g. the bone or metal implants) are in the x-ray beam. Usually, a beam-hardening correction (BHC) method is used to suppress the artifacts induced by bone or other objects of high attenuation, in which a calibration-oriented iterative operation is carried out to determine a set of parameters for all situations. Based on the Helgasson-Ludwig consistency condition (HLCC), an optimization based method has been proposed by turning the calibration-oriented iterative operation of BHC into solving an optimization problem sustained by projection data. However, the optimization based HLCC-BHC method demands the engagement of a large number of neighboring projection views acquired at relatively high and uniform angular sampling rate, hindering its application in situations where the angular sampling in projection view is sparse or non-uniform. By defining an objective function based on the data integral invariant constraint (DIIC), we again turn BHC into solving an optimization problem sustained by projection data. As it only needs a pair of projection views at any view angle, the proposed BHC method can be applicable in the challenging scenarios mentioned above. Using the projection data simulated by computer, we evaluate and verify the proposed optimization based DIIC-BHC method's performance. Moreover, with the projection data of a head scan by a multi-detector row MDCT, we show the proposed DIIC-BHC method's utility in clinical applications.