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


C# DataTable.BeginInit方法代碼示例

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


在下文中一共展示了DataTable.BeginInit方法的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");
		}
開發者ID:carrie901,項目名稱:mono,代碼行數:54,代碼來源:DataSetTest2.cs

示例2: 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;
		}
開發者ID:Dawn-of-Light,項目名稱:Puzzle.NET,代碼行數:55,代碼來源:ObjectQueryEngine.cs

示例3: 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;
        }
開發者ID:devlights,項目名稱:Sazare,代碼行數:18,代碼來源:DataTableExtensionsSample01.cs

示例4: 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);
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:30,代碼來源:DataViewTest.cs

示例5: 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);
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:22,代碼來源:DataViewTest.cs

示例6: 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);
		}
開發者ID:symform,項目名稱:mono,代碼行數:15,代碼來源:DataTableTest.cs

示例7: 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");
			*/
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:38,代碼來源:ConstraintCollectionTest.cs

示例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");
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:16,代碼來源:DataTableTest2.cs

示例9: 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");
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:15,代碼來源:DataTableTest2.cs

示例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");
			}
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:26,代碼來源:DataTableTest2.cs

示例11: 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");
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:16,代碼來源:DataTableTest2.cs

示例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");
		}
開發者ID:ItsVeryWindy,項目名稱:mono,代碼行數:22,代碼來源:DataViewTest.cs

示例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"));

                }
開發者ID:jjenki11,項目名稱:blaze-chem-rendering,代碼行數:40,代碼來源:ConstraintCollectionTest.cs

示例14: Excute


//.........這裏部分代碼省略.........
             throw new SAPException(Messages.Nodatacouldbeselected, exception);
         }
         if (exception.Message.Equals("DATA_TO_MEMORY_NOT_POSSIBLE"))
         {
             throw new SAPException(Messages.ErrorduringSAPmemoryallocation, exception);
         }
         throw new SAPException(exception.Key + exception.Message);
     }
     this._Fields.Clear();
     string str = "";
     foreach (IRfcStructure structure2 in function.GetTable("LISTDESC").ToList())
     {
         if (str == "")
         {
             str = structure2["LID"].GetValue().ToString();
         }
         if (structure2["LID"].GetValue().ToString() == str)
         {
             bool flag = false;
             for (int k = 0; k < this._Fields.Count; k++)
             {
                 if (this._Fields[k].Name.Equals(structure2["FNAMEINT"].GetValue().ToString()))
                 {
                     flag = true;
                 }
             }
             if (!flag)
             {
                 this._Fields.Add(new QueryField(structure2["FNAMEINT"].GetValue().ToString(), structure2["FTYP"].GetValue().ToString(), Convert.ToInt32(structure2["FLEN"].GetValue().ToString()), Convert.ToInt32(structure2["FDEC"].GetValue().ToString()), structure2["FDESC"].GetValue().ToString()));
             }
         }
     }
     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;
開發者ID:SyedMdKamruzzaman,項目名稱:sap_interface,代碼行數:67,代碼來源:Query.cs

示例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();
 }
開發者ID:SDRC-India,項目名稱:sdrcdevinfo,代碼行數:14,代碼來源:RangeCheckReportGenerator.cs


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