从数据表中删除列 [英] remove columns from datatable
本文介绍了从数据表中删除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据表有几个字段,即field1,field2,field3,field9,field10,field88 ...
string strData =field1,field2,field3,...;
问题:
循环遍历数据表的列,我想删除strData中的列。
因此数据表最终得到以下列:
field9, field10,field88 ...
HOW是上面用C#完成的吗?
谢谢
解决方案
使用这个
dt.Columns.Remove
其中dt是DataTable
谢谢
--RA
你想从数据库表或DataTable对象中删除这些列吗?
在第一种情况下你必须使用SMO:
http://msdn.microsoft.com/en- us / library / ms204453.aspx [ ^ ]
在第二种情况下将此字符串拆分为数组并循环遍历此数组:
DataTable t = ...
foreach ( string col in cols)
{
t.Columns.Remove(col);
}
cols
变量表示列名的字符串数组
Hi,
A datatable has several fields, i.e. field1, field2, field3, field9, field10, field88...
string strData = "field1, field2, field3, ...";
Question:
looping through the columns of the datatable, I would like to remove the columns in strData.
So the datatable ends up with the following columns:
field9, field10, field88...
HOw is the above done in C# please?
Thanks
解决方案
use this
dt.Columns.Remove
where dt is DataTable
Thanks
--RA
Hi,
do you want to remove this columns from database table or from DataTable object?
in first case you have to use SMO:
http://msdn.microsoft.com/en-us/library/ms204453.aspx[^]
in second case just split this string into array and loop through this array :
DataTable t = ... foreach(string col in cols) { t.Columns.Remove(col); }
cols
variable represents string array of column names
这篇关于从数据表中删除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文