c#dataview遍历_c# – 列出DataView

这篇博客介绍了如何将列表转换为DataTable并创建DataView的方法。首先通过BuildDataTable方法将IList类型的列表转换成DataTable,接着利用DataTable的DefaultView属性获取DataView。示例中展示了针对List的转换过程。
摘要由CSDN通过智能技术生成

我的建议是将列表转换为DataTable,然后使用表的默认视图构建您的DataView.

首先,你必须建立数据表:

// is the type of data in the list.

// If you have a List,for example,then call this as follows:

// List ListOfInt;

// DataTable ListTable = BuildDataTable(ListOfInt);

public static DataTable BuildDataTable(IList lst)

{

//create DataTable Structure

DataTable tbl = CreateTable();

Type entType = typeof(T);

PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entType);

//get the list item and add into the list

foreach (T item in lst)

{

DataRow row = tbl.NewRow();

foreach (PropertyDescriptor prop in properties)

{

row[prop.Name] = prop.GetValue(item);

}

tbl.Rows.Add(row);

}

return tbl;

}

private static DataTable Cre

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值