创建具有不同条目的 DataTable 或 DataView
我有以下 XML 文件,
<Department>
<dept>
<category>HR</category>
<performance>8.2</performance>
<month>3</month>
</dept>
<dept>
<category>Marketing</category>
<performance>8.8</performance>
<month>3</month>
</dept>
<dept>
<category>HR</category>
<performance>7.2</performance>
<month>4</month>
</dept>
<dept>
<category>Admin</category>
<performance>8.9</performance>
<month>4</month>
</dept>
</Department>
我可以将 XML 读入 DataTable 并从中创建 DataView。但我想做以下事情:
只要类别重复(例如 HR 重复两次),只考虑一条记录并平均绩效点。所以记录应该是
HR 7.7
营销8.8
Admin 8.9
由于 HR 重复了两次,所以我对其进行了平均。
我想在从 XML 文件创建 DataTable 或 DataView 时指定此条件。怎么办?
I have the following XML file
<Department>
<dept>
<category>HR</category>
<performance>8.2</performance>
<month>3</month>
</dept>
<dept>
<category>Marketing</category>
<performance>8.8</performance>
<month>3</month>
</dept>
<dept>
<category>HR</category>
<performance>7.2</performance>
<month>4</month>
</dept>
<dept>
<category>Admin</category>
<performance>8.9</performance>
<month>4</month>
</dept>
</Department>
I am able to read the XML into a DataTable and create a DataView out of it. But I want to do the following:
Wherever Category is repeated (like HR is repeated twice), consider only one record and average the performance points. So the record should be like
HR 7.7
Marketing 8.8
Admin 8.9
Here since HR was repeated twice, I averaged it out.
I want to specify this condition while creating a DataTable or DataView out of the XML file. How to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过
.ToTable()
?签出:
--编辑--
http://izlooite.blogspot.com /2010/10/how-to-distinct-sum-count-datatable-for.html
给出:
HR 7.7
营销 8.8
管理 8.9
Did you try
.ToTable()
?Checkout:
--EDIT--
http://izlooite.blogspot.com/2010/10/how-to-distinct-sum-count-datatable-for.html
Gives:
HR 7.7
Marketing 8.8
Admin 8.9