从数据表在C#中删除列 [英] Remove columns from DataTable in C#

查看:111
本文介绍了从数据表在C#中删除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集,我得到了我传递从一个函数调用回一个DataTable。它有15-20列,不过我只想数据的10列。

有没有办法删除,我不希望这些列,数据表复制到另一个具有只定义了我想要的列或只是更好地遍历集合,只是使用我需要的列。

我需要写出来的值到一个固定长度的数据文件。


解决方案

除了限制选择以减少带宽和内存的列:


 的DataTable吨;
       t.Columns.Remove(COLUMNNAME);
       t.Columns.RemoveAt(参数:columnIndex);


I have a DataSet which I get a DataTable from that I am being passed back from a function call. It has 15-20 columns, however I only want 10 columns of the data.

Is there a way to remove those columns that I don't want, copy the DataTable to another that has only the columns defined that I want or is it just better to iterate the collection and just use the columns I need.

I need to write the values out to a fixed length data file.

解决方案

Aside from limiting the columns selected to reduce bandwidth and memory:

       DataTable t;
       t.Columns.Remove("columnName");
       t.Columns.RemoveAt(columnIndex);

这篇关于从数据表在C#中删除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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