This paper constructs an analytical framework of digital transformation affecting enterprise ESG performance based on the investment perspective. And empirical analyses are conducted using firm-level panel data of Chinese A-share listed companies from 2009 to 2020 in the China's Stock Markets. It is found that digital transformation significantly improves enterprise ESG performance. Digital transformation improves enterprise ESG performance by enhancing risk-taking capacity, mitigating agency conflicts, and suppressing management overconfidence. Heterogeneity analyses show that the effects of digital transformation on capital investment efficiency and firms' ESG performance are more pronounced among firms in mature and declining stages. Digital transformation has a significant impact on capital investment efficiency and corporate ESG performance in both technology-intensive and capital-intensive firms. These findings are crucial for understanding the key role of digital transformation in shaping long-term economic growth potential and sustainability from an investment perspective.