Thursday, May 23, 2013

To Remove a column from DataTable or Dataset in asp.net


To check whether column exists or not in DataTable or Dataset in Asp.net

For Dataset:
DataSet ds = new DataSet();

ds = GetData();

ds.Tables[0].Columns.Remove("EmpName");

Alternative way:
ds.Tables[0].Columns.RemoveAt(columnIndex);


For DataTable:
DataTable dt = new DataTable();
dt = GetData();

dt.Columns.Remove("EmpName");

Alternative way:
dt.Columns.RemoveAt(columnIndex);

No comments:

Post a Comment