I am using C#. I want to hide or remove the column from DataTable or DataSet . I attach my partial code:
DataTable dt = new DataTable();
DataView dv = new DataView();
dv = (DataView)Session["map_hi"];
dt = dv.ToTable();
dt.Columns[0].ColumnMapping = MappingType.Hidden;
dt.AcceptChanges();
try this
DataTable t;
t.Columns.Remove("columnName");
t.Columns.RemoveAt(columnIndex);
As Pranay says you can remove columns as myTable.Columns.Remove("columnName");
But in my case it throws an exception as "Cannot remove this column, because it is part of the parent key for relationship"
I was able to overcome it as below.
myTable.ParentRelations.Clear();
myTable.ChildRelations.Clear();
myTable.Constraints.Clear();
myTable.Columns.Remove("columnName");
Hope this will help someone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With