Пример #1
0
 /// <summary>
 /// remove col: heatArea, name1.
 /// </summary>
 ///
 /// <param name="dt"></param>
 private void RemoveColumns(DataTable dt)
 {
     if (dt != null)
     {
         DataColumnCollection cols = dt.Columns;
         if (cols.Contains("heatArea"))
         {
             if (cols.CanRemove(cols["heatArea"]))
             {
                 cols.Remove("heatArea");
             }
         }
         if (cols.Contains("Name1"))
         {
             if (cols.CanRemove(cols["Name1"]))
             {
                 cols.Remove("Name1");
             }
         }
     }
 }
Пример #2
0
    //<Snippet1>
    private void RemoveColumn(string columnName, DataTable table)
    {
        DataColumnCollection columns = table.Columns;

        if (columns.Contains(columnName))
        {
            if (columns.CanRemove(columns[columnName]))
            {
                columns.Remove(columnName);
            }
        }
    }
Пример #3
0
        public void CanRemove()
        {
            DataTable            table  = new DataTable("test_table");
            DataTable            table2 = new DataTable("test_table_2");
            DataColumnCollection cols   = table.Columns;
            DataColumn           c      = new DataColumn("test1");

            cols.Add();

            // MSDN says that if C doesn't belong to Cols
            // Exception is thrown.
            Assert.False(cols.CanRemove(c));

            cols.Add(c);
            Assert.True(cols.CanRemove(c));

            c            = new DataColumn();
            c.Expression = "test1 + 2";
            cols.Add(c);

            c = cols["test2"];
            Assert.False(cols.CanRemove(c));

            c = new DataColumn("t");
            table2.Columns.Add(c);
            DataColumnCollection Cols2 = table2.Columns;

            Assert.True(Cols2.CanRemove(c));

            DataSet Set = new DataSet();

            Set.Tables.Add(table);
            Set.Tables.Add(table2);
            DataRelation Rel = new DataRelation("Rel", table.Columns[0], table2.Columns[0]);

            Set.Relations.Add(Rel);

            Assert.False(Cols2.CanRemove(c));
            Assert.False(cols.CanRemove(null));
        }
Пример #4
0
        public void CanRemove()
        {
            DataTable            Table  = new DataTable("test_table");
            DataTable            Table2 = new DataTable("test_table_2");
            DataColumnCollection Cols   = Table.Columns;
            DataColumn           C      = new DataColumn("test1");

            Cols.Add();

            // LAMESPEC: MSDN says that if C doesn't belong to Cols
            // Exception is thrown.
            Assert.False(Cols.CanRemove(C));

            Cols.Add(C);
            Assert.True(Cols.CanRemove(C));

            C            = new DataColumn();
            C.Expression = "test1 + 2";
            Cols.Add(C);

            C = Cols["test2"];
            Assert.False(Cols.CanRemove(C));

            C = new DataColumn("t");
            Table2.Columns.Add(C);
            DataColumnCollection Cols2 = Table2.Columns;

            Assert.True(Cols2.CanRemove(C));

            DataSet Set = new DataSet();

            Set.Tables.Add(Table);
            Set.Tables.Add(Table2);
            DataRelation Rel = new DataRelation("Rel", Table.Columns[0], Table2.Columns[0]);

            Set.Relations.Add(Rel);

            Assert.False(Cols2.CanRemove(C));
            Assert.False(Cols.CanRemove(null));
        }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 private void RemoveID()
 {
     if (dt != null)
     {
         DataColumnCollection cols = dt.Columns;
         if (cols.Contains("id"))
         {
             if (cols.CanRemove(cols["id"]))
             {
                 cols.Remove("id");
             }
         }
     }
 }
Пример #6
0
    // <Snippet1>
    private void RemoveColumnByName(string columnName)
    {
        // Get the DataColumnCollection from a DataTable in a DataSet.
        DataColumnCollection columns =
            ds.Tables["Suppliers"].Columns;

        if (columns.Contains(columnName))
        {
            if (columns.CanRemove(columns[columnName]))
            {
                columns.Remove(columnName);
            }
        }
    }