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"))); }
/// <summary> /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </summary> /// <returns> /// true if <paramref name="item"/> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. This method also returns false if <paramref name="item"/> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </returns> /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception> public bool Remove(FeatureDataTable item) { if (_dataTables.CanRemove(item)) { _dataTables.Remove(item); return(true); } return(false); }
// <Snippet1> private void RemoveTables() { // Set the name of the table to test for and remove. string name = "Suppliers"; // Presuming a DataGrid is displaying more than one table, get its DataSet. DataSet thisDataSet = (DataSet)DataGrid1.DataSource; DataTableCollection tablesCol = thisDataSet.Tables; if (tablesCol.Contains(name) && tablesCol.CanRemove(tablesCol[name])) { tablesCol.Remove(name); } }
private void pmbtn_Click(object sender, System.EventArgs e) { int rowCnt, i; DataTable bookTable; DataRow row; string s1; if (isoTB.Text.Trim() == "") { return; } DataTableCollection tablesCol = bookdSet.Tables; if (tablesCol.Contains("book") && tablesCol.CanRemove(tablesCol["book"])) { tablesCol.Remove("book"); } if (isoTB.Text.Trim() == "0") { sqlComm.CommandText = "SELECT book.ID, book.书名, book.文种号, book.图书分类号, book.种次号, borrow.副本, borrow.借出时间, borrow.归还时间, borrow.续借次数, borrow.电话, borrow.Ecode AS ISO编号, borrow.中文姓名 FROM book INNER JOIN borrow ON book.文种号 = borrow.文种号 AND book.种次号 = borrow.种次号 AND book.图书分类号 = borrow.图书分类号 WHERE (borrow.Ecode = '" + isoTB.Text.Trim() + "') AND (borrow.实际归还时间 IS NULL) AND (归还时间<'" + System.DateTime.Now.ToString() + "') AND (borrow.中文姓名 = '" + nmTB.Text.Trim() + "')"; sqlDataAdap.SelectCommand = sqlComm; sqlDataAdap.Fill(bookdSet, "book"); bookDG.CaptionText = "查询人员:(" + isoTB.Text.Trim().ToUpper() + ")"; dv.Table = bookdSet.Tables["book"]; this.bookDG.DataSource = dv; return; } //sqlhrComm.CommandText="SELECT employees.ecode, employees.ecname, codeorgs.cdptname FROM employees INNER JOIN codeorgs ON employees.dept = codeorgs.dptno WHERE (employees.ecode = '"+isoTB.Text.Trim()+"')"; //sqlhrConn.Open(); //sqldr=sqlhrComm.ExecuteReader(); OracleComm.CommandText = "select v_sys_psn.psncode, v_sys_psn.psnname, v_sys_dept.first_deptname, v_sys_dept.second_deptname, v_sys_dept.third_deptname, v_sys_psn.mobile, v_sys_psn.officephone, v_sys_corp.UNITNAME from v_sys_psn LEFT OUTER JOIN V_SYS_DEPT ON v_sys_psn.pk_deptdoc = v_sys_dept.pk_fourtdept LEFT OUTER JOIN v_sys_corp ON v_sys_psn.PK_CORP=v_sys_corp.PK_CORP where v_sys_psn.psncode=N'" + isoTB.Text.Trim().PadLeft(5, '0') + "' ";//写好想执行的Sql语句 OracleConn.Open(); odr = OracleComm.ExecuteReader(); if (odr.Read()) { booktv.BeginUpdate(); booktv.Nodes.Clear(); TreeNode rootNode1 = new TreeNode("所借图书", 5, 5); booktv.Nodes.Add(rootNode1); TreeNode rootNode = new TreeNode("人员信息"); booktv.Nodes.Add(rootNode); s1 = odr.GetValue(1).ToString(); TreeNode tnBook1 = new TreeNode("姓名:" + odr.GetValue(1).ToString()); rootNode.Nodes.Add(tnBook1); TreeNode tnBook2 = new TreeNode("部门:" + odr.GetValue(7).ToString() + "-" + odr.GetValue(2).ToString() + "-" + odr.GetValue(3).ToString() + "-" + odr.GetValue(4).ToString()); rootNode.Nodes.Add(tnBook2); TreeNode tnBook3 = new TreeNode("电话:" + odr.GetValue(5).ToString() + " " + odr.GetValue(6).ToString()); rootNode.Nodes.Add(tnBook3); booktv.EndUpdate(); rootNode.Expand(); //sqldr.Close(); //sqlhrConn.Close(); odr.Close(); OracleConn.Close(); sqlComm.CommandText = "SELECT book.ID, book.书名, book.文种号, book.图书分类号, book.种次号, borrow.副本, borrow.借出时间, borrow.归还时间, borrow.续借次数, borrow.电话, borrow.Ecode AS ISO编号 FROM book INNER JOIN borrow ON book.文种号 = borrow.文种号 AND book.种次号 = borrow.种次号 AND book.图书分类号 = borrow.图书分类号 WHERE (borrow.Ecode = '" + isoTB.Text.Trim() + "') AND (borrow.实际归还时间 IS NULL) AND (归还时间<'" + System.DateTime.Now.ToString() + "')"; sqlDataAdap.SelectCommand = sqlComm; sqlDataAdap.Fill(bookdSet, "book"); bookDG.CaptionText = "查询人员:(" + isoTB.Text.Trim().ToUpper() + ")"; dv.Table = bookdSet.Tables["book"]; this.bookDG.DataSource = dv; } else { MessageBox.Show("没有该人员!"); odr.Close(); OracleConn.Close(); } }
private void bmbtn_Click(object sender, System.EventArgs e) { int rowCnt, i; DataTable bookTable; DataRow row; string s1; if (wzhTB.Text.Trim() == "" || tsflhTB.Text.Trim() == "" || zchTB.Text.Trim() == "") { return; } DataTableCollection tablesCol = bookdSet.Tables; if (tablesCol.Contains("book") && tablesCol.CanRemove(tablesCol["book"])) { tablesCol.Remove("book"); } sqlComm.CommandText = "SELECT ID, 书名, 第一责任者, 出版者, 借出书量, 借出次数, 馆藏量 FROM book WHERE (文种号 = N'" + wzhTB.Text.Trim().ToUpper() + "') AND (图书分类号 = N'" + tsflhTB.Text.Trim().ToUpper() + "') AND (种次号 = N'" + zchTB.Text.Trim().ToUpper() + "')"; sqlConn.Open(); sqldr = sqlComm.ExecuteReader(); if (sqldr.Read()) { booktv.BeginUpdate(); booktv.Nodes.Clear(); TreeNode rootNode = new TreeNode("图书信息"); booktv.Nodes.Add(rootNode); TreeNode tnBook1 = new TreeNode("书名:" + sqldr.GetValue(1).ToString()); rootNode.Nodes.Add(tnBook1); TreeNode tnBook2 = new TreeNode("第一责任者:" + sqldr.GetValue(2).ToString()); rootNode.Nodes.Add(tnBook2); TreeNode tnBook3 = new TreeNode("出版者:" + sqldr.GetValue(3).ToString()); rootNode.Nodes.Add(tnBook3); TreeNode tnBook4 = new TreeNode("借出书量:" + sqldr.GetValue(4).ToString() + " 借出次数:" + sqldr.GetValue(5).ToString() + " 馆藏量:" + sqldr.GetValue(6).ToString()); rootNode.Nodes.Add(tnBook4); booktv.EndUpdate(); rootNode.Expand(); sqldr.Close(); sqlConn.Close(); sqlComm.CommandText = "SELECT 借出时间, 归还时间,续借次数, 电话, Ecode AS ISO编号,副本,中文姓名 FROM borrow WHERE (文种号 = N'" + wzhTB.Text.Trim().ToUpper() + "') AND (图书分类号 = N'" + tsflhTB.Text.Trim().ToUpper() + "') AND (种次号 = N'" + zchTB.Text.Trim().ToUpper() + "') AND (实际归还时间 IS NULL) AND (归还时间<'" + System.DateTime.Now.ToString() + "')"; sqlDataAdap.SelectCommand = sqlComm; sqlDataAdap.Fill(bookdSet, "book"); bookDG.CaptionText = "查询图书:(" + wzhTB.Text.Trim().ToUpper() + " " + tsflhTB.Text.Trim().ToUpper() + " " + zchTB.Text.Trim().ToUpper() + ")"; dv.Table = bookdSet.Tables["book"]; dv.Table.Columns.Add("姓名"); dv.Table.Columns.Add("部门"); for (rowCnt = 0; rowCnt < dv.Table.Rows.Count; rowCnt++) { row = dv.Table.Rows[rowCnt]; s1 = row["ISO编号"].ToString().Trim(); if (s1 != "0") { //sqlhrComm.CommandText="SELECT employees.ecode, employees.ecname, codeorgs.cdptname FROM employees INNER JOIN codeorgs ON employees.dept = codeorgs.dptno WHERE (employees.ecode = '"+s1+"')"; //sqlhrConn.Open(); //sqldr=sqlhrComm.ExecuteReader(); //sqldr.Read(); //if(sqldr.HasRows) //{ // row["姓名"]=sqldr.GetValue(1).ToString(); // row["部门"]=sqldr.GetValue(2).ToString(); //} //sqlhrConn.Close(); //sqldr.Close(); OracleComm.CommandText = "select v_sys_psn.psncode, v_sys_psn.psnname, v_sys_dept.first_deptname, v_sys_dept.second_deptname, v_sys_dept.third_deptname, v_sys_psn.mobile, v_sys_psn.officephone, v_sys_corp.UNITNAME from v_sys_psn LEFT OUTER JOIN V_SYS_DEPT ON v_sys_psn.pk_deptdoc = v_sys_dept.pk_fourtdept LEFT OUTER JOIN v_sys_corp ON v_sys_psn.PK_CORP=v_sys_corp.PK_CORP where v_sys_psn.psncode=N'" + s1.PadLeft(5, '0') + "' ";//写好想执行的Sql语句 OracleConn.Open(); odr = OracleComm.ExecuteReader(); if (odr.HasRows) { odr.Read(); row["姓名"] = odr.GetValue(1).ToString(); row["部门"] = odr.GetValue(7).ToString() + "-" + odr.GetValue(2).ToString() + "-" + odr.GetValue(3).ToString() + "-" + odr.GetValue(4).ToString(); } odr.Close(); OracleConn.Close(); } } this.bookDG.DataSource = dv; } else { MessageBox.Show("没有该图书!"); sqlConn.Close(); } }
private void maturebtn_Click_1(object sender, System.EventArgs e) { int rowCnt, i; DataTable bookTable; DataRow row; string s1; DataTableCollection tablesCol = bookdSet.Tables; if (tablesCol.Contains("book") && tablesCol.CanRemove(tablesCol["book"])) { tablesCol.Remove("book"); } booktv.BeginUpdate(); booktv.Nodes.Clear(); booktv.EndUpdate(); sqlComm.CommandText = "SELECT book.ID, book.书名, book.文种号, book.图书分类号, book.种次号,borrow.副本, borrow.借出时间,borrow.归还时间,borrow.续借次数 ,borrow.电话, borrow.Ecode AS ISO编号, borrow.中文姓名 FROM book INNER JOIN borrow ON book.文种号 = borrow.文种号 AND book.种次号 = borrow.种次号 AND book.图书分类号 = borrow.图书分类号 WHERE (borrow.实际归还时间 IS NULL) AND (borrow.归还时间 < '" + System.DateTime.Now.ToString() + "') ORDER BY borrow.借出时间"; sqlDataAdap.SelectCommand = sqlComm; sqlDataAdap.Fill(bookdSet, "book"); bookDG.CaptionText = "查询所有未还图书"; dv.Table = bookdSet.Tables["book"]; dv.Table.Columns.Add("姓名"); dv.Table.Columns.Add("部门"); for (rowCnt = 0; rowCnt < dv.Table.Rows.Count; rowCnt++) { row = dv.Table.Rows[rowCnt]; s1 = row["ISO编号"].ToString().Trim(); if (s1 != "0") { //sqlhrComm.CommandText="SELECT employees.ecode, employees.ecname, codeorgs.cdptname FROM employees INNER JOIN codeorgs ON employees.dept = codeorgs.dptno WHERE (employees.ecode = '"+s1+"')"; //sqlhrConn.Open(); //sqldr=sqlhrComm.ExecuteReader(); //sqldr.Read(); //if(sqldr.HasRows) //{ // row["姓名"]=sqldr.GetValue(1).ToString(); // row["部门"]=sqldr.GetValue(2).ToString(); //} //sqlhrConn.Close(); //sqldr.Close(); OracleComm.CommandText = "select v_sys_psn.psncode, v_sys_psn.psnname, v_sys_dept.first_deptname, v_sys_dept.second_deptname, v_sys_dept.third_deptname, v_sys_psn.mobile, v_sys_psn.officephone, v_sys_corp.UNITNAME from v_sys_psn LEFT OUTER JOIN V_SYS_DEPT ON v_sys_psn.pk_deptdoc = v_sys_dept.pk_fourtdept LEFT OUTER JOIN v_sys_corp ON v_sys_psn.PK_CORP=v_sys_corp.PK_CORP where v_sys_psn.psncode=N'" + s1.PadLeft(5, '0') + "' ";//写好想执行的Sql语句 OracleConn.Open(); odr = OracleComm.ExecuteReader(); if (odr.HasRows) { odr.Read(); row["姓名"] = odr.GetValue(1).ToString(); row["部门"] = odr.GetValue(7).ToString() + "-" + odr.GetValue(2).ToString() + "-" + odr.GetValue(3).ToString() + "-" + odr.GetValue(4).ToString(); } odr.Close(); OracleConn.Close(); } } this.bookDG.DataSource = dv; }