Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to add particular columns to DaTable.
C#
ds.ReadXml(@"D:\Sample.xml");
dt.Columns.Add(ds.Tables[0].Columns[0].ToString());
dt.Columns.Add(ds.Tables[0].Columns[9].ToString());
dt.Columns.Add(ds.Tables[0].Columns[10].ToString());

But it's giving me only column names, not data.
Please help
Posted

1 solution

when you do something like above it will not add any data but will add only column to datatable.
rather than try below

C#
ds.ReadXml(@"D:\Sample.xml");

dt = ds.tables[0].copy();


this will copy both structure and data from table 0 to your datatable object. if you want to copy the structure only try using clone method insted of copy.

mark answer if it helpful.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900