public void RemoveAt() { DataTableCollection tbcol = _dataset[0].Tables; tbcol.Add(_tables[0]); tbcol.Add("table1"); try { tbcol.RemoveAt(-1); Assert.False(true); } catch (IndexOutOfRangeException e) { } try { tbcol.RemoveAt(101); Assert.False(true); } catch (IndexOutOfRangeException e) { } tbcol.RemoveAt(1); Assert.Equal(1, tbcol.Count); tbcol.RemoveAt(0); Assert.Equal(0, tbcol.Count); }
public void RemoveAt() { DataTableCollection tbcol = _dataset[0].Tables; tbcol.Add(_tables[0]); tbcol.Add("table1"); try { tbcol.RemoveAt(-1); Fail("the index was out of bound: must have failed"); } catch (IndexOutOfRangeException e) { } try { tbcol.RemoveAt(101); Fail("the index was out of bound: must have failed"); } catch (IndexOutOfRangeException e) { } tbcol.RemoveAt(1); AssertEquals("test#5", 1, tbcol.Count); tbcol.RemoveAt(0); AssertEquals("test#6", 0, tbcol.Count); }
public void RemoveAt() { DataTableCollection tbcol = _dataset[0].Tables; tbcol.Add(_tables[0]); tbcol.Add("table1"); Assert.Throws <IndexOutOfRangeException>(() => tbcol.RemoveAt(-1)); Assert.Throws <IndexOutOfRangeException>(() => tbcol.RemoveAt(101)); tbcol.RemoveAt(1); Assert.Equal(1, tbcol.Count); tbcol.RemoveAt(0); Assert.Equal(0, tbcol.Count); }
/// <summary> /// 过滤 /// </summary> /// <param name="dts"></param> /// <param name="filter"></param> /// <returns></returns> public static void Remove(this DataTableCollection dts, Func <DataTable, bool> filter) { HashSet <int> tbIndexs = new HashSet <int>(); int index = 0; foreach (DataTable dt in dts) { if (!filter(dt)) { tbIndexs.Add(index); } index++; } foreach (int tbIndex in tbIndexs) { dts.RemoveAt(tbIndex); } }
/// <summary> /// Populates the collection. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="classInfo">The class info.</param> /// <param name="collection">The collection.</param> /// <param name="dataSet">The data set.</param> protected static void PopulateCollection <T>(ClassInfo classInfo, MetaStorageCollectionBase <T> collection, DataSet dataSet) where T : OrderGroup { #region ArgumentNullExceptions if (dataSet == null) { throw new ArgumentNullException("dataSet"); } #endregion DataTableCollection tables = dataSet.Tables; if (tables == null || tables.Count == 0) { return; } // Get the collection that contains ids of all items returned DataRowCollection dataRowCol = tables[0].Rows; // No ids returned if (dataRowCol == null || dataRowCol.Count == 0) { return; } int numberOfRecords = dataRowCol.Count; int[] idArray = new int[numberOfRecords]; // Populate array for (int index = 0; index < numberOfRecords; index++) { idArray[index] = (int)dataRowCol[index]["OrderGroupId"]; } // Remove id collection tables.RemoveAt(0); // Map table names foreach (DataTable table in dataSet.Tables) { if (table.Rows.Count > 0) { table.TableName = table.Rows[0]["TableName"].ToString(); } } // Cycle through id Collection foreach (int id in idArray) { string filter = String.Format("OrderGroupId = '{0}'", id.ToString()); // Populate the meta object data first // Meta data will be always in the second table returned DataView view = DataHelper.CreateDataView(dataSet.Tables["OrderGroup"], filter); // Only read one record, since we are populating only one object // reader.Read(); // Create instance of the object specified and populate it T obj = (T)classInfo.CreateInstance(); obj.Load(view[0]); collection.Add(obj); // Populate collections within object obj.PopulateCollections(dataSet.Tables, filter); /* * if (dataSet.Tables.Count != 0) * { * throw new ArgumentOutOfRangeException("Tables", "Stored Procedure returned too many tables"); * } * */ } }
public void RemoveAt(Int32 index) { _tables.RemoveAt(index); }