查询一个DataSet [英] Query a DataSet

查看:167
本文介绍了查询一个DataSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在读从XML文件中的数据到一个强类型的DataSet 。在多个表中的数据结束了;我可以运行对其进行查询,以创建一个非规范化视图在的DataGrid



显示

样品输入:



<预类=郎咸平的XML prettyprint-覆盖> < PeopleFile>
<地址>
<街道> 123有些街道< /街道>
<城市与GT;与北京市东城区的LT; /镇>
<&居住GT;
<第一>简< /第一>
<最后> Doe的LT; /最后>
< /驻地>
<&居住GT;
<第一>约翰和LT; /第一>
<最后> Doe的LT; /最后>
< /驻地>
< /地址>
<地址>
<街道> 456树街< /街道>
<城市与GT;&韦斯特伍德LT; /镇>
<&居住GT;
<第一>&玛丽LT; /第一>
<最后>琼斯 - 史密斯和LT; /最后>
< /驻地>
<&居住GT;
<第一>麦克< /第一>
<最后>史密斯和LT; /最后>
< /驻地>
<&居住GT;
<第一>凯特LT; /第一>
<最后>史密斯和LT; /最后>
< /驻地>
< /地址>
< / PeopleFile>



所需的输出:



<预类=郎-none prettyprint-覆盖> 123一些街头北京市东城Jane Doe的
123的一些街道北京市东城李四
456树街韦斯特伍德玛丽·琼斯,史密斯
456树街迈克·韦斯特伍德史密斯
456树街维斯特伍德凯特·史密斯

编辑:我要补充的是,除了多每个文件表,我真正的数据也被这AFAIK将需要被加载到单独的数据集


解决方案

是,使用Linq。有一组特殊的扩展名为LINQ到数据集。



您需要.NET 3.5明显,并添加使用System.Data这;



如果您的多个文件都遵循相同的模式,你应该能够将其读入TypedDataSet的单独实例和合并()这些实例。


I'm reading data from XML files into a strong typed DataSet. The data ends up in multiple tables; can I run queries against it to create a denormalized view to display in a DataGrid?

Sample input:

<PeopleFile>
    <address>
        <street>123 Some Street</street>
        <town>Anytown</town>
        <resident>
            <first>Jane</first>
            <last>Doe</last>
        </resident>
        <resident>
            <first>John</first>
            <last>Doe</last>
        </resident>
    </address>
    <address>
        <street>456 Tree Street</street>
        <town>Westwood</town>
        <resident>
            <first>Mary</first>
            <last>Jones-Smith</last>
        </resident>
        <resident>
            <first>Mike</first>
            <last>Smith</last>
        </resident>
        <resident>
            <first>Kate</first>
            <last>Smith</last>
        </resident>
    </address>
</PeopleFile>

Desired output:

123 Some Street Anytown     Jane    Doe  
123 Some Street Anytown     John    Doe  
456 Tree Street Westwood    Mary    Jones-Smith  
456 Tree Street Westwood    Mike    Smith  
456 Tree Street Westwood    Kate    Smith  

EDIT: I should add that in addition to multiple tables per file, my real data is also split among multiple files which AFAIK will require being loaded into separate DataSets.

解决方案

Yes, use Linq. There is a special set of extensions called Linq-to-Datasets.

You will need .NET 3.5 obviously, and add using System.Data;

If your multiple files follow the same schema you should be able to read them into separate instances of the TypedDataSet and Merge() those instances.

这篇关于查询一个DataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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