效果:


一、前言
在 Winform 平台,可以用 DataGridView 这样的控件来显示数据库的表单数据,但在 C# 控制台项目中,如果有用到数据库查询,我们想看看查询语句的效果,就比较困难了,比如,我随意写了一个控制台输出,代码如下:
using System.Data;
namespace CSharpConnectMySQL
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string sql = "SELECT * FROM goods_type";
            DataSet dataSet = MySqlHelper.GetDataSet(sql);
            DataTable dt = dataSet.Tables[0];
            if(dt.Rows.Count > 0)
            {
                //打印所有列名
                string columnName = string.Empty;
                for (int i = 0; i < dt.Columns.Count; i++)
                {
           


















