从DataSet向DataTable添加特定列 [英] Add particular columns to DataTable from DataSet

查看:70
本文介绍了从DataSet向DataTable添加特定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试将特定列添加到DaTable。

Hi,

I am trying to add particular columns to DaTable.

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

推荐答案

当您执行上述操作时,它不会添加任何数据,但只会向数据表添加列。

而不是尝试下面



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

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

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





这会将表0中的结构和数据复制到数据表对象。如果你想复制结构只尝试使用复制的克隆方法。



如果有用则标记答案。



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.


这篇关于从DataSet向DataTable添加特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆