当前位置: 首页>>代码示例>>C#>>正文


C# DataColumn.ToString方法代码示例

本文整理汇总了C#中DataColumn.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# DataColumn.ToString方法的具体用法?C# DataColumn.ToString怎么用?C# DataColumn.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataColumn的用法示例。


在下文中一共展示了DataColumn.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddRange

        public void AddRange()
        {
            DataTable Table = new DataTable("test_table");
            DataTable Table2 = new DataTable("test_table2");
            DataColumnCollection Cols = Table.Columns;
            DataColumn C = null;
            DataColumn[] ColArray = new DataColumn[2];

            C = new DataColumn("test1");
            ColArray[0] = C;

            C = new DataColumn("test2");
            C.AllowDBNull = false;
            C.Caption = "Test_caption";
            C.DataType = typeof(XmlReader);
            ColArray[1] = C;

            Cols.AddRange(ColArray);

            C = Cols[0];
            Assert.True(C.AllowDBNull);
            Assert.False(C.AutoIncrement);
            Assert.Equal(0L, C.AutoIncrementSeed);
            Assert.Equal(1L, C.AutoIncrementStep);
            Assert.Equal("test1", C.Caption);
            Assert.Equal("Element", C.ColumnMapping.ToString());
            Assert.Equal("test1", C.ColumnName);
            Assert.Null(C.Container);
            Assert.Equal(typeof(string), C.DataType);
            Assert.Equal(DBNull.Value, C.DefaultValue);
            Assert.False(C.DesignMode);
            Assert.Equal("", C.Expression);
            Assert.Equal(0, C.ExtendedProperties.Count);
            Assert.Equal(-1, C.MaxLength);
            Assert.Equal("", C.Namespace);
            Assert.Equal(0, C.Ordinal);
            Assert.Equal("", C.Prefix);
            Assert.False(C.ReadOnly);
            Assert.Null(C.Site);
            Assert.Equal("test_table", C.Table.TableName);
            Assert.Equal("test1", C.ToString());
            Assert.False(C.Unique);

            C = Cols[1];
            Assert.False(C.AllowDBNull);
            Assert.False(C.AutoIncrement);
            Assert.Equal(0L, C.AutoIncrementSeed);
            Assert.Equal(1L, C.AutoIncrementStep);
            Assert.Equal("Test_caption", C.Caption);
            Assert.Equal("Element", C.ColumnMapping.ToString());
            Assert.Equal("test2", C.ColumnName);
            Assert.Null(C.Container);
            Assert.Equal(typeof(XmlReader), C.DataType);
            Assert.Equal(DBNull.Value, C.DefaultValue);
            Assert.False(C.DesignMode);
            Assert.Equal("", C.Expression);
            Assert.Equal(0, C.ExtendedProperties.Count);
            Assert.Equal(-1, C.MaxLength);
            Assert.Equal("", C.Namespace);
            Assert.Equal(1, C.Ordinal);
            Assert.Equal("", C.Prefix);
            Assert.False(C.ReadOnly);
            Assert.Null(C.Site);
            Assert.Equal("test_table", C.Table.TableName);
            Assert.Equal("test2", C.ToString());
            Assert.False(C.Unique);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:67,代码来源:DataColumnCollectionTest.cs

示例2: Add

        public void Add()
        {
            var Table = new DataTable("test_table");
            DataColumnCollection cols = Table.Columns;
            DataColumn c = null;
            cols.Add();
            cols.Add();

            for (int i = 0; i < 2; i++)
            {
                c = cols[i];
                Assert.True(c.AllowDBNull);
                Assert.False(c.AutoIncrement);
                Assert.Equal(0L, c.AutoIncrementSeed);
                Assert.Equal(1L, c.AutoIncrementStep);
                Assert.Equal($"Column{i + 1}", c.Caption);
                Assert.Equal("Element", c.ColumnMapping.ToString());
                Assert.Equal($"Column{i + 1}", c.ColumnName);
                Assert.Null(c.Container);
                Assert.Equal(typeof(string), c.DataType);
                Assert.Equal(DBNull.Value, c.DefaultValue);
                Assert.False(c.DesignMode);
                Assert.Equal("", c.Expression);
                Assert.Equal(0, c.ExtendedProperties.Count);
                Assert.Equal(-1, c.MaxLength);
                Assert.Equal("", c.Namespace);
                Assert.Equal(i, c.Ordinal);
                Assert.Equal("", c.Prefix);
                Assert.False(c.ReadOnly);
                Assert.Null(c.Site);
                Assert.Equal("test_table", c.Table.TableName);
                Assert.Equal($"Column{i + 1}", c.ToString());
                Assert.False(c.Unique);
            }

            cols.Add("test1", typeof(int), "");
            cols.Add("test2", typeof(string), "Column1 + Column2");

            c = cols[2];
            Assert.True(c.AllowDBNull);
            Assert.False(c.AutoIncrement);
            Assert.Equal(0L, c.AutoIncrementSeed);
            Assert.Equal(1L, c.AutoIncrementStep);
            Assert.Equal("test1", c.Caption);
            Assert.Equal("Element", c.ColumnMapping.ToString());
            Assert.Equal("test1", c.ColumnName);
            Assert.Null(c.Container);
            Assert.Equal(typeof(int), c.DataType);
            Assert.Equal(DBNull.Value, c.DefaultValue);
            Assert.False(c.DesignMode);
            Assert.Equal("", c.Expression);
            Assert.Equal(0, c.ExtendedProperties.Count);
            Assert.Equal(-1, c.MaxLength);
            Assert.Equal("", c.Namespace);
            Assert.Equal(2, c.Ordinal);
            Assert.Equal("", c.Prefix);
            Assert.False(c.ReadOnly);
            Assert.Null(c.Site);
            Assert.Equal("test_table", c.Table.TableName);
            Assert.Equal("test1", c.ToString());
            Assert.False(c.Unique);

            c = cols[3];
            Assert.True(c.AllowDBNull);
            Assert.False(c.AutoIncrement);
            Assert.Equal(0L, c.AutoIncrementSeed);
            Assert.Equal(1L, c.AutoIncrementStep);
            Assert.Equal("test2", c.Caption);
            Assert.Equal("Element", c.ColumnMapping.ToString());
            Assert.Equal("test2", c.ColumnName);
            Assert.Null(c.Container);
            Assert.Equal(typeof(string), c.DataType);
            Assert.Equal(DBNull.Value, c.DefaultValue);
            Assert.False(c.DesignMode);
            Assert.Equal("Column1 + Column2", c.Expression);
            Assert.Equal(0, c.ExtendedProperties.Count);
            Assert.Equal(-1, c.MaxLength);
            Assert.Equal("", c.Namespace);
            Assert.Equal(3, c.Ordinal);
            Assert.Equal("", c.Prefix);
            Assert.True(c.ReadOnly);
            Assert.Null(c.Site);
            Assert.Equal("test_table", c.Table.TableName);
            Assert.Equal("test2 + Column1 + Column2", c.ToString());
            Assert.False(c.Unique);

            c = new DataColumn("test3", typeof(int));
            cols.Add(c);

            c = cols[4];
            Assert.True(c.AllowDBNull);
            Assert.False(c.AutoIncrement);
            Assert.Equal(0L, c.AutoIncrementSeed);
            Assert.Equal(1L, c.AutoIncrementStep);
            Assert.Equal("test3", c.Caption);
            Assert.Equal("Element", c.ColumnMapping.ToString());
            Assert.Equal("test3", c.ColumnName);
            Assert.Null(c.Container);
            Assert.Equal(typeof(int), c.DataType);
            Assert.Equal(DBNull.Value, c.DefaultValue);
//.........这里部分代码省略.........
开发者ID:dotnet,项目名称:corefx,代码行数:101,代码来源:DataColumnCollectionTest.cs

示例3: TestToString

        public void TestToString()
        {
            DataColumn dc;
            string sColName, sExp;
            dc = new DataColumn();

            //ToString = ColumnName 			
            sColName = "Test1";
            dc.ColumnName = sColName;
            // ToString - ColumnName
            Assert.Equal(sColName, dc.ToString());

            //TosTring = ColumnName + " + " + Expression
            sExp = "Tax * 1.234";
            dc.Expression = sExp;
            // TosTring=ColumnName + Expression
            Assert.Equal(sColName + " + " + sExp, dc.ToString());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:18,代码来源:DataColumnTest2.cs


注:本文中的DataColumn.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。