當前位置: 首頁>>代碼示例>>C#>>正文


C# DataTable.GetStringRepresentation方法代碼示例

本文整理匯總了C#中System.Data.DataTable.GetStringRepresentation方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.GetStringRepresentation方法的具體用法?C# DataTable.GetStringRepresentation怎麽用?C# DataTable.GetStringRepresentation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Data.DataTable的用法示例。


在下文中一共展示了DataTable.GetStringRepresentation方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetStringRepresentation_WhenDbNull_PrintsNull

        public void GetStringRepresentation_WhenDbNull_PrintsNull()
        {
            var table = new DataTable();
            table.Columns.Add("id", typeof(int));
            table.Columns.Add("name", typeof(string));
            table.Columns.Add("very long column name", typeof(string));

            table.Rows.Add(1, "f", "a");
            table.Rows.Add(2, "the longest", DBNull.Value);
            table.Rows.Add(3, "g", "c");

            var rep = table.GetStringRepresentation();

            rep.Should().Be(
                "+----+-------------+-----------------------+" + Environment.NewLine +
                "| id | name        | very long column name |" + Environment.NewLine +
                "+----+-------------+-----------------------+" + Environment.NewLine +
                "| 1  | f           | a                     |" + Environment.NewLine +
                "| 2  | the longest | NULL                  |" + Environment.NewLine +
                "| 3  | g           | c                     |" + Environment.NewLine +
                "+----+-------------+-----------------------+" + Environment.NewLine);
        }
開發者ID:DataTableFormatters,項目名稱:DataTableFormatters,代碼行數:22,代碼來源:DataTableExtensionsTests.cs

示例2: GetStringRepresentation_WhenCustomFormat_Success

        public void GetStringRepresentation_WhenCustomFormat_Success()
        {
            var table = new DataTable();
            table.Columns.Add("id", typeof(int));
            table.Columns.Add("name", typeof(string));
            table.Columns.Add("very long column name", typeof(double));

            table.Rows.Add(1, "f", 1.0);
            table.Rows.Add(2, "the longest", 2.3456);
            table.Rows.Add(3, "g", -98765);

            var rep = table.GetStringRepresentation(
                new RightAlign("id"),
                new CustomFormat("very long column name", "#.00"));

            rep.Should().Be(
                "+----+-------------+-----------------------+" + Environment.NewLine +
                "| id | name        | very long column name |" + Environment.NewLine +
                "+----+-------------+-----------------------+" + Environment.NewLine +
                "|  1 | f           | 1.00                  |" + Environment.NewLine +
                "|  2 | the longest | 2.35                  |" + Environment.NewLine +
                "|  3 | g           | -98765.00             |" + Environment.NewLine +
                "+----+-------------+-----------------------+" + Environment.NewLine);
        }
開發者ID:DataTableFormatters,項目名稱:DataTableFormatters,代碼行數:24,代碼來源:DataTableExtensionsTests.cs

示例3: GetStringRepresentation_WhenTableWithoutRows_Success

        public void GetStringRepresentation_WhenTableWithoutRows_Success()
        {
            var table = new DataTable();
            table.Columns.Add("id", typeof(int));
            table.Columns.Add("name", typeof(string));
            table.Columns.Add("very long column name", typeof(string));

            var rep = table.GetStringRepresentation();

            rep.Should().Be(
                "+----+------+-----------------------+" + Environment.NewLine +
                "| id | name | very long column name |" + Environment.NewLine +
                "+----+------+-----------------------+" + Environment.NewLine +
                "+----+------+-----------------------+" + Environment.NewLine);
        }
開發者ID:DataTableFormatters,項目名稱:DataTableFormatters,代碼行數:15,代碼來源:DataTableExtensionsTests.cs

示例4: GetStringRepresentation_WhenTableWithoutColumns_Success

        public void GetStringRepresentation_WhenTableWithoutColumns_Success()
        {
            var table = new DataTable();

            var rep = table.GetStringRepresentation();

            rep.Should().Be(
                "+--+" + Environment.NewLine +
                "|  |" + Environment.NewLine +
                "+--+" + Environment.NewLine +
                "+--+" + Environment.NewLine);
        }
開發者ID:DataTableFormatters,項目名稱:DataTableFormatters,代碼行數:12,代碼來源:DataTableExtensionsTests.cs


注:本文中的System.Data.DataTable.GetStringRepresentation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。