当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Filtering a DataTable and inserting the result into another datatable

问题描述:

I am working on a dataset with has several records in it and I have a method which accepts a datatable as an input parameter.

For example, I have a dataset named dsDetails and one of the table in it is Charges with the following data

Type Rate Name

B 14 bbb

A 10 ABC

C 12 ccc

I am passing the above datatable to my c# method as follows

Populate(dsDetails.Tables["Charges"]);

Everything looks fine, but now that I want to filter the above datatable by type and want to pass the datatable with records of Type=A

May I know good way to do that to pass a filtered datatable?

网友答案:

You probably want to use a DataView object for that:

DataView dv = new DataView(dsDetails.Tables["Charges"]);
dv.RowFilter = "Type = 'A'";
Populate(dv.ToTable());
分享给朋友:
您可能感兴趣的文章:
随机阅读: