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


C# DataTable.BeginInit方法代码示例

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


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

示例1: BeginInit2

        public void BeginInit2()
        {
            DataTable table = new DataTable("table");
            DataView dv = new DataView();
            DataColumn col1 = new DataColumn("col1");
            DataColumn col2 = new DataColumn("col2");

            _dvInitialized = false;

            dv.Initialized += new EventHandler(OnDataViewInitialized);

            dv.BeginInit();
            table.BeginInit();
            table.Columns.AddRange(new DataColumn[] { col1, col2 });

            dv.Table = table;
            Assert.Null(dv.Table);
            dv.EndInit();

            Assert.Null(dv.Table);
            Assert.Equal(0, table.Columns.Count);

            table.EndInit();

            dv.Initialized -= new EventHandler(OnDataViewInitialized); // this should not be unregistered before table.EndInit().

            Assert.Equal(2, table.Columns.Count);
            Assert.Equal(table, dv.Table);
            Assert.Equal(true, _dvInitialized);
        }
开发者ID:ericeil,项目名称:corefx,代码行数:30,代码来源:DataViewTest.cs

示例2: BeginInit

        public void BeginInit()
        {
            DataTable table = new DataTable("table");
            DataView dv = new DataView();
            DataColumn col1 = new DataColumn("col1");
            DataColumn col2 = new DataColumn("col2");

            dv.BeginInit();
            table.BeginInit();
            table.Columns.AddRange(new DataColumn[] { col1, col2 });

            dv.Table = table;
            Assert.Null(dv.Table);
            dv.EndInit();

            Assert.Null(dv.Table);
            Assert.Equal(0, table.Columns.Count);

            table.EndInit();
            Assert.Equal(table, dv.Table);
            Assert.Equal(2, table.Columns.Count);
        }
开发者ID:ericeil,项目名称:corefx,代码行数:22,代码来源:DataViewTest.cs

示例3: BeginInitTest

        public void BeginInitTest()
        {
            DataSet ds = new DataSet();

            DataTable table1 = new DataTable("table1");
            DataTable table2 = new DataTable("table2");

            DataColumn col1 = new DataColumn("col1", typeof(int));
            DataColumn col2 = new DataColumn("col2", typeof(int));
            table1.Columns.Add(col1);
            table2.Columns.Add(col2);

            UniqueConstraint pkey = new UniqueConstraint("pk", new string[] { "col1" }, true);
            ForeignKeyConstraint fkey = new ForeignKeyConstraint("fk", "table1", new string[] { "col1" },
                                new string[] { "col2" }, AcceptRejectRule.Cascade,
                                Rule.Cascade, Rule.Cascade);
            DataRelation relation = new DataRelation("rel", "table1", "table2", new string[] { "col1" },
                                 new string[] { "col2" }, false);
            ds.BeginInit();
            table1.BeginInit();
            table2.BeginInit();

            ds.Tables.AddRange(new DataTable[] { table1, table2 });
            ds.Relations.AddRange(new DataRelation[] { relation });

            table1.Constraints.AddRange(new Constraint[] { pkey });
            table2.Constraints.AddRange(new Constraint[] { fkey });

            // The tables/relations shud not get added to the DataSet yet
            Assert.Equal(0, ds.Tables.Count);
            Assert.Equal(0, ds.Relations.Count);
            Assert.Equal(0, table1.Constraints.Count);
            Assert.Equal(0, table2.Constraints.Count);
            ds.EndInit();

            Assert.Equal(2, ds.Tables.Count);
            Assert.Equal(1, ds.Relations.Count);
            Assert.Equal(1, ds.Tables[0].Constraints.Count);
            Assert.Equal(1, ds.Tables[1].Constraints.Count);

            // Table shud still be in BeginInit .. 
            DataColumn col3 = new DataColumn("col2");
            UniqueConstraint uc = new UniqueConstraint("uc", new string[] { "col2" }, false);

            table1.Columns.AddRange(new DataColumn[] { col3 });
            table1.Constraints.AddRange(new Constraint[] { uc });

            Assert.Equal(1, table1.Columns.Count);
            Assert.Equal(1, table1.Constraints.Count);

            table1.EndInit();
            Assert.Equal(2, table1.Columns.Count);
            Assert.Equal(2, table1.Columns.Count);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:54,代码来源:DataSetTest2.cs

示例4: TableInitializedEventTest4

 public void TableInitializedEventTest4()
 {
     DataTable dt = new DataTable();
     Assert.True(dt.IsInitialized);
     dt.BeginInit();
     _tableInitialized = false;
     dt.Initialized += new EventHandler(OnTableInitialized);
     dt.Columns.Add("Series Label", typeof(SqlInt32));
     dt.Rows.Add(new object[] { 123 });
     Assert.False(dt.IsInitialized);
     dt.EndInit();
     Assert.True(dt.IsInitialized);
     Assert.True(_tableInitialized);
     dt.Initialized -= new EventHandler(OnTableInitialized);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:DataTableTest.cs

示例5: EndInit

        [Fact] // "Even after EndInit(), .NET does not fill Table property on UniqueConstraint.")]
        public void TestAddRange2()
        {
            var table = new DataTable("Table");
            var column1 = new DataColumn("col1");
            var column2 = new DataColumn("col2");
            var column3 = new DataColumn("col3");
            table.Columns.Add(column1);
            table.Columns.Add(column2);
            table.Columns.Add(column3);
            string[] columnNames = { "col1", "col2", "col3" };

            var constraints = new Constraint[3];
            constraints[0] = new UniqueConstraint("Unique1", column1);
            constraints[1] = new UniqueConstraint("Unique2", column2);
            constraints[2] = new UniqueConstraint("Unique3", columnNames, true);

            table.BeginInit();
            table.Constraints.AddRange(constraints);

            //Check the table property of UniqueConstraint Object
            try
            {
                Assert.Null(constraints[2].Table);
            }
            catch (NullReferenceException) { }

            table.EndInit();
        }
开发者ID:dotnet,项目名称:corefx,代码行数:29,代码来源:ConstraintCollectionTest.cs


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