Hi everybody,
Supposing I have a DataTable with the following columns ["A", "B",
"C", "D"].
I need to copy that DataTable with all its data but filtered by
columns, that is I want
to have a new DataTable with all rows and the columns ["A", "C"].
What can I do?
Bye!
Manish Bafna - 27 Aug 2007 12:24 GMT
Hi,
you can try code something like this below:
DataTable dt = new DataTable();
DataColumn col1 = new DataColumn();
DataColumn col2 = new DataColumn();
col1.ColumnName = "Name";
col2.ColumnName = "Age";
col1.DataType = typeof(System.String);
col2.DataType = typeof(System.Int32);
col2.ColumnMapping = MappingType.Hidden;
dt.Columns.Add(col1);
dt.Columns.Add(col2);
DataRow row1 = dt.NewRow();
row1["Name"] = "manih bafna";
dt.Rows.Add(row1);
dataGrid1.DataSource = dt;

Signature
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.
> Hi everybody,
> Supposing I have a DataTable with the following columns ["A", "B",
[quoted text clipped - 6 lines]
>
> Bye!
Chris Shepherd - 27 Aug 2007 13:44 GMT
> Hi everybody,
> Supposing I have a DataTable with the following columns ["A", "B",
[quoted text clipped - 4 lines]
>
> What can I do?
You could copy the DataTable in its entirety, and then remove the
columns you don't need.
For example:
DataTable newDT = oldDT.Copy();
newDT.Columns.Remove("B");
newDT.Columns.Remove("D");
someObj.someMethod(newDT);
Chris.