本文整理汇总了C#中DataSet.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.BeginInit方法的具体用法?C# DataSet.BeginInit怎么用?C# DataSet.BeginInit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSet
的用法示例。
在下文中一共展示了DataSet.BeginInit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}