本文整理匯總了C#中System.Data.DataTable.EndInit方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.EndInit方法的具體用法?C# DataTable.EndInit怎麽用?C# DataTable.EndInit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.EndInit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: BeginInitTest
[Test] 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.AreEqual (0, ds.Tables.Count, "#1");
Assert.AreEqual (0, ds.Relations.Count, "#2");
Assert.AreEqual (0, table1.Constraints.Count, "#3");
Assert.AreEqual (0, table2.Constraints.Count, "#4");
ds.EndInit ();
Assert.AreEqual (2, ds.Tables.Count, "#5");
Assert.AreEqual (1, ds.Relations.Count, "#6");
Assert.AreEqual (1, ds.Tables [0].Constraints.Count, "#7");
Assert.AreEqual (1, ds.Tables [1].Constraints.Count, "#8");
// 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.AreEqual (1, table1.Columns.Count, "#9");
Assert.AreEqual (1, table1.Constraints.Count, "#10");
table1.EndInit ();
Assert.AreEqual (2, table1.Columns.Count, "#11");
Assert.AreEqual (2, table1.Columns.Count, "#12");
}
示例2: BuildSampleTable
private DataTable BuildSampleTable()
{
var table = new DataTable();
table.BeginInit();
table.Columns.Add("COL-1", typeof(int));
table.Columns.Add("COL-2");
table.EndInit();
table.BeginLoadData();
for (var i = 0; i < 5; i++)
{
table.LoadDataRow(new object[] {i, (i + 1).ToString()}, true);
}
table.EndLoadData();
return table;
}
示例3: 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;
AssertNull ("#1", dv.Table);
dv.EndInit ();
AssertNull ("#2", dv.Table);
AssertEquals ("#3", 0, table.Columns.Count);
table.EndInit ();
dv.Initialized -= new EventHandler (OnDataViewInitialized); // this should not be unregistered before table.EndInit().
AssertEquals ("#4", 2, table.Columns.Count);
AssertEquals ("#6", table, dv.Table);
AssertEquals ("DataViewInitialized #5", true, dvInitialized);
}
示例4: 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;
AssertNull ("#1", dv.Table);
dv.EndInit ();
AssertNull ("#2", dv.Table); // still.
AssertEquals ("#3", 0, table.Columns.Count);
table.EndInit ();
AssertEquals ("#5", table, dv.Table);
AssertEquals ("#4", 2, table.Columns.Count);
}
示例5: TableInitializedEventTest4
public void TableInitializedEventTest4 ()
{
DataTable dt = new DataTable();
Assert.IsTrue (dt.IsInitialized, "TableInitialized #04");
dt.BeginInit ();
tableInitialized = false;
dt.Initialized += new EventHandler (OnTableInitialized);
dt.Columns.Add("Series Label", typeof(SqlInt32));
dt.Rows.Add(new object[] {"sss"});
Assert.IsFalse (dt.IsInitialized, "TableInitialized #05");
dt.EndInit ();
Assert.IsTrue (dt.IsInitialized, "TableInitialized #06");
Assert.IsTrue (tableInitialized, "TableInitialized #07");
dt.Initialized -= new EventHandler (OnTableInitialized);
}
示例6: TestAddRange2
public void TestAddRange2 ()
{
DataTable table = new DataTable ("Table");
DataColumn column1 = new DataColumn ("col1");
DataColumn column2 = new DataColumn ("col2");
DataColumn column3 = new DataColumn ("col3");
table.Columns.Add (column1);
table.Columns.Add (column2);
table.Columns.Add (column3);
string [] columnNames = {"col1", "col2", "col3"};
Constraint [] 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 ();
//Console.WriteLine(table.InitStatus == DataTable.initStatus.BeginInit);
table.Constraints.AddRange (constraints);
//Check the table property of UniqueConstraint Object
try {
Assert.That (constraints [2].Table, Is.Null, "#A01");
} catch (Exception e) {
Assert.That (e, Is.TypeOf (typeof(NullReferenceException)), "#A02");
}
table.EndInit ();
// After EndInit is called the constraints associated with most recent call to AddRange() must be
// added to the ConstraintCollection
/* dunno if the above is true, but it crashes on .NET either. Disabling.
Assert.That (constraints [2].Table.ToString (), Is.EqualTo ("Table"), "#A03");
Assert.That (table.Constraints.Contains ("Unique1"), Is.True, "#A04");
Assert.That (table.Constraints.Contains ("Unique3"), Is.True, "#A06");
Assert.That (table.Constraints.Contains ("Unique2"), Is.True, "#A05");
*/
}
示例7: BeginInit_PrimaryKey_3
public void BeginInit_PrimaryKey_3 ()
{
DataTable table = new DataTable ();
DataColumn col1 = table.Columns.Add ("col1", typeof (int));
DataColumn col2 = table.Columns.Add ("col2", typeof (int));
// ms.net behavior
table.BeginInit ();
UniqueConstraint uc = new UniqueConstraint (string.Empty, new String[] {"col1"}, true);
table.Constraints.AddRange (new Constraint[] {uc});
table.PrimaryKey = new DataColumn [] {col2};
table.EndInit ();
Assert.AreEqual ("col1", table.PrimaryKey[0].ColumnName, "#1");
}
示例8: BeginInit_Cols_Constraints
public void BeginInit_Cols_Constraints ()
{
DataTable table = new DataTable ();
// if both cols and constraints are added after BeginInit, the cols
// should be added, before the constraints are added/validated
table.BeginInit ();
DataColumn col1 = new DataColumn ("col1", typeof (int));
table.Columns.AddRange (new DataColumn[] {col1});
UniqueConstraint uc = new UniqueConstraint (string.Empty, new String[] {"col1"}, false);
table.Constraints.AddRange (new Constraint[] {uc});
// no exception shud be thrown
table.EndInit ();
Assert.AreEqual (1, table.Constraints.Count, "#1");
}
示例9: BeginInit_PrimaryKey_1
public void BeginInit_PrimaryKey_1 ()
{
DataTable table = new DataTable ();
DataColumn col = table.Columns.Add ("col", typeof (int));
table.PrimaryKey = new DataColumn[] {col};
table.AcceptChanges ();
Assert.AreEqual (1, table.PrimaryKey.Length, "#1");
table.BeginInit ();
DataColumn col2 = new DataColumn ("col2", typeof (int));
table.Columns.AddRange (new DataColumn[] {col2});
table.PrimaryKey = new DataColumn[] {col2};
table.EndInit ();
Assert.AreEqual (1, table.PrimaryKey.Length, "#2");
Assert.AreEqual ("col2", table.PrimaryKey[0].ColumnName, "#3");
}
示例10: BeginInit_PrimaryKey_2
public void BeginInit_PrimaryKey_2()
{
DataTable table = new DataTable ();
DataColumn col = table.Columns.Add ("col", typeof (int));
table.PrimaryKey = new DataColumn[] {col};
table.AcceptChanges ();
// ms.net behavior.
table.BeginInit ();
DataColumn col1 = new DataColumn ("col1", typeof (int));
table.Columns.AddRange (new DataColumn[] {col1});
UniqueConstraint uc = new UniqueConstraint (string.Empty, new String[] {"col1"}, true);
table.Constraints.AddRange (new Constraint[] {uc});
try {
table.EndInit ();
Assert.Fail ("#1");
} catch (ArgumentException ex) {
// Cannot add primary key constraint since primary
// key is already set for the table
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNull (ex.ParamName, "#5");
}
}
示例11: GetDataTable
public virtual DataTable GetDataTable(NPathSelectQuery query, IList sourceList)
{
FixQuery(query);
DataTable resultTable = new DataTable();
resultTable.BeginInit();
#region build columns
int id = 0;
foreach (NPathSelectField field in query.Select.SelectFields)
{
string fieldName = field.Alias;
NPathIdentifier path = field.Expression as NPathIdentifier;
if (path != null)
{
if (path.IsWildcard)
{
throw new Exception("this can not happen"); // do not localize
}
else
{
if (fieldName == null)
fieldName = path.Path;
resultTable.Columns.Add(path.Path, typeof (object));
}
}
else
{
if (fieldName == null)
{
fieldName = "col" + id.ToString();
id++;
}
resultTable.Columns.Add(fieldName, typeof (object));
}
}
#endregion
resultTable.EndInit();
resultTable.BeginLoadData();
IList resultList = InternalGetTable(query, sourceList);
foreach (object[] values in resultList)
{
resultTable.Rows.Add(values);
}
resultTable.EndLoadData();
return resultTable;
}
示例12: 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.IsNull (dv.Table, "#1");
dv.EndInit ();
Assert.IsNull (dv.Table, "#2"); // still.
Assert.AreEqual (0, table.Columns.Count, "#3");
table.EndInit ();
Assert.AreEqual (table, dv.Table, "#4");
Assert.AreEqual (2, table.Columns.Count, "#5");
}
示例13: TestAddRange2
// Even after EndInit(), MS.NET does not fill Table property
// on UniqueConstraint.
public void TestAddRange2()
{
DataTable table = new DataTable ("Table");
DataColumn column1 = new DataColumn ("col1");
DataColumn column2 = new DataColumn ("col2");
DataColumn column3 = new DataColumn ("col3");
table.Columns.Add (column1);
table.Columns.Add (column2);
table.Columns.Add (column3);
string []columnNames = {"col1", "col2", "col3"};
Constraint []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();
//Console.WriteLine(table.InitStatus == DataTable.initStatus.BeginInit);
table.Constraints.AddRange (constraints);
//Check the table property of UniqueConstraint Object
try{
Assertion.AssertNull ("#01", constraints [2].Table);
}
catch (Exception e) {
Assertion.Assert ("#A02", "System.NullReferenceException".Equals (e.GetType().ToString()));
}
table.EndInit();
// After EndInit is called the constraints associated with most recent call to AddRange() must be
// added to the ConstraintCollection
Assertion.Assert ("#A03", constraints [2].Table.ToString().Equals ("Table"));
Assertion.Assert ("#A04", table.Constraints.Contains ("Unique1"));
Assertion.Assert ("#A05", table.Constraints.Contains ("Unique2"));
Assertion.Assert ("#A06", table.Constraints.Contains ("Unique3"));
}
示例14: Excute
//.........這裏部分代碼省略.........
}
}
}
DataTable dt = new DataTable();
dt.BeginInit();
for (int i = 0; i < this._Fields.Count; i++)
{
string name = this._Fields[i].Name;
DataColumn column = new DataColumn(name)
{
Caption = this._Fields[i].Description
};
if (this._Fields[i].ABAPType.Equals("I"))
{
column.DataType = Type.GetType("System.Int32");
}
else if (this._Fields[i].ABAPType.Equals("F"))
{
column.DataType = Type.GetType("System.Double");
}
else if (this._Fields[i].ABAPType.Equals("P"))
{
column.DataType = Type.GetType("System.Decimal");
}
else
{
column.DataType = Type.GetType("System.String");
}
if (!this.SpalteVorhanden(dt, name))
{
dt.Columns.Add(column);
}
}
dt.EndInit();
int startIndex = 0;
int num5 = 0;
int length = 0;
int num7 = 0;
string str3 = "";
string str4 = "";
bool flag2 = true;
IRfcStructure structure3 = null;
if (function.GetTable("LDATA").RowCount > 0)
{
DataRow row = dt.NewRow();
while (flag2)
{
IRfcTable tb = function.GetTable("LDATA");
structure3 = function.GetTable("LDATA")[num7];
str3 = structure3["LINE"].GetValue().ToString().PadRight(0x41a);
string str5 = str3.Substring(startIndex, 3);
if (str5.Contains(":") && (startIndex > 1))
{
startIndex--;
str5 = str3.Substring(startIndex, 3);
}
if (str5.Contains(":") && (startIndex > 1))
{
startIndex--;
str5 = str3.Substring(startIndex, 3);
}
if (str5.Equals(" "))
{
if (num7 < (function.GetTable("LDATA").RowCount - 1))
{
num7++;
示例15: RenameColumn
/// <summary>
/// Rename DataTable Column with Required Value
/// </summary>
/// <param name="Table"></param>
private void RenameColumn(ref DataTable Table)
{
Table.BeginInit();
Table.Columns[0].ColumnName = this.ColumnsHeader[DRCColumnsHeader.Time];
Table.Columns[1].ColumnName = this.ColumnsHeader[DRCColumnsHeader.AreaId];
Table.Columns[2].ColumnName = this.ColumnsHeader[DRCColumnsHeader.AreaName];
Table.Columns[3].ColumnName = this.ColumnsHeader[DRCColumnsHeader.DataValue];
Table.Columns[4].ColumnName = this.ColumnsHeader[DRCColumnsHeader.Source];
Table.EndInit();
}