public void Clear() { DataTableCollection tbcol = _dataset[0].Tables; tbcol.Add(_tables[0]); tbcol.Clear(); Assert.Equal(0, tbcol.Count); tbcol.AddRange(new DataTable[] { _tables[0], _tables[1] }); tbcol.Clear(); Assert.Equal(0, tbcol.Count); }
public static DataTable ExcelToDataTable(string fileName, string sheetName) { //open file and returns as Stream FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read); //Createopenxmlreader via ExcelReaderFactory IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); //.xlsx //excelReader.IsFirstRowAsColumnNames = true; //Set the First Row as Column Name var conf = new ExcelDataSetConfiguration { ConfigureDataTable = _ => new ExcelDataTableConfiguration { UseHeaderRow = true } }; //Return as DataSet DataSet result = excelReader.AsDataSet(conf); //Get all the Tables DataTableCollection table = result.Tables; //Store it in DataTable DataTable resultTable = table[sheetName]; table.Clear(); result.Clear(); excelReader.Close(); stream.Dispose(); return(resultTable); }
// <Snippet1> private void ClearTables() { // Get the DataSet of a DataGrid control. DataSet dataSet = (DataSet)DataGrid1.DataSource; DataTableCollection tables = dataSet.Tables; // Clear the collection. tables.Clear(); }
public void Contains() { DataTableCollection tbcol = _dataset[0].Tables; tbcol.Clear(); /* _tables is array of DataTables defined in Setup */ tbcol.AddRange(_tables); string tblname = ""; /* checking for a recently input table, expecting true */ Assert.Equal(true, tbcol.Contains(_tables[0].TableName)); /* trying to check with a empty string, expecting false */ Assert.Equal(false, tbcol.Contains(tblname)); /* trying to check for a table that donot exist, expecting false */ Assert.Equal(false, tbcol.Contains("InvalidTableName")); }
public void CanRemove() { DataTableCollection tbcol = _dataset[0].Tables; tbcol.Clear(); /* _tables is array of DataTables defined in Setup */ tbcol.AddRange(_tables); DataTable tbl = null; /* checking for a recently input table, expecting true */ Assert.Equal(true, tbcol.CanRemove(_tables[0])); /* trying to check with a null reference, expecting false */ Assert.Equal(false, tbcol.CanRemove(tbl)); /* trying to check with a table that does not exist in collection, expecting false */ Assert.Equal(false, tbcol.CanRemove(new DataTable("newTable"))); }
public void Remove() { DataTableCollection tbcol = _dataset[0].Tables; tbcol.Clear(); /* _tables is array of DataTables defined in Setup */ tbcol.AddRange(_tables); /* removing a recently added table */ int count = tbcol.Count; tbcol.Remove(_tables[0]); Assert.Equal(count - 1, tbcol.Count); DataTable tbl = null; /* removing a null reference. must generate an Exception */ Assert.Throws <ArgumentNullException>(() => tbcol.Remove(tbl)); /* removing a table that is not there in collection */ Assert.Throws <ArgumentException>(() => tbcol.Remove(new DataTable("newTable"))); }
public void AddRange() { DataTableCollection tbcol = _dataset[0].Tables; tbcol.Clear(); /* _tables is array of type DataTable defined in Setup */ tbcol.AddRange(_tables); int i, j; i = 0; foreach (DataTable table in tbcol) { Assert.Equal(_tables[i].TableName, table.TableName); j = 0; foreach (DataColumn column in table.Columns) { Assert.Equal(_tables[i].Columns[j].ColumnName, column.ColumnName); j++; } i++; } }
public void Remove() { DataTableCollection tbcol = _dataset[0].Tables; tbcol.Clear(); /* _tables is array of DataTables defined in Setup */ tbcol.AddRange(_tables); /* removing a recently added table */ int count = tbcol.Count; tbcol.Remove(_tables[0]); Assert.Equal(count - 1, tbcol.Count); DataTable tbl = null; /* removing a null reference. must generate an Exception */ try { tbcol.Remove(tbl); Assert.False(true); } catch (Exception e) { Assert.Equal(typeof(ArgumentNullException), e.GetType()); } /* removing a table that is not there in collection */ try { tbcol.Remove(new DataTable("newTable")); Assert.False(true); } catch (Exception e) { Assert.Equal(typeof(ArgumentException), e.GetType()); } }
/// <summary> /// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </summary> /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. </exception> public void Clear() { _dataTables.Clear(); }
public void Clear() { _tables.Clear(); }