如何在XML中查询解决方案中的临时表 [英] How to Query a Temp Table within a solution from XML

查看:70
本文介绍了如何在XML中查询解决方案中的临时表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

我有一个无法连接到数据库的小项目所以我b $ b有项目运行所需的数据,保存到XML文件中

在根目录下VB Net中的项目/解决方案。我能够在运行时将XML数据加载到临时表中,但无法找到通过代码查询临时表的方式。在项目中临时表的查询的简单示例将是一个很好的例子。



表格设置如下......



1)AutoID * Key

2)名称为字符串

3)文件路径为字符串

4)计为整数

5)键入字符串



以下将数据放入页面上的表格中,但是我想要找到一种方法来预先查询/过滤这个数据。我会

喜欢按名字(AZ)来奥得。



<前lang =vb> Dim DS As DataSet
DS = DataSet()

DS.ReadXml(appPath + \ data.xml
Dim i 作为 整数
对于 i = 0 DS.Tables( 0 )。Rows.Count - 1
Console.WriteLine(DS .Tables( 0 )。行(i).Item( 1 ))
下一步
DataGrid1.DataSource = DS





我知道他们是可能是一种方式o使用我创建的dataSource

来完成此操作。但我还想要一个简单的例子,说明如何通过代码执行

a查询选择*来自TableA,其中Name ='Mike'



感谢您的帮助。

解决方案

尝试使用linq到xml?

  Dim  partNos = _ 
来自商品 purchaseOrder ...< Item> _
其中(item。< Quantity> .Value * _
item。< USPrice> .Value)> 100 _
按项目排序。< PartNumber> .Value _
选择 item



我从MSDN复制了这段代码。如需进一步了解,请参阅 http://msdn.microsoft.com/en-us/library/bb387061.aspx [ ^ ]


I have a small project that is not able to connect to a database so I
have the data necessary for the project to run, saved into an XML file
in the root directory of the project/solution in VB Net. I am able to
load the XML data into a temporary table at runtime but am unable to locate a
way to query the temp table via code. An simple example of a query to
a temp table within a project would be nice.

The Table is set up as follows...

1) AutoID *Key
2) Name as string
3) Filepath as string
4) Count as integer
5) Type as string

The following places the data into a table on the page but I
am looking for a way to query/filter this before hand. I would
like to Oder it by Name (A-Z).

Dim DS As DataSet
        DS = New DataSet()

        DS.ReadXml(appPath + "\data.xml")
        Dim i As Integer
        For i = 0 To DS.Tables(0).Rows.Count - 1
            Console.WriteLine(DS.Tables(0).Rows(i).Item(1))
        Next
        DataGrid1.DataSource = DS



I know that they is probably a way to do this using the dataSource
I created. But I would also like a plain example of how to perform
a query via code to "Select * From TableA where Name = 'Mike'"

Thanks for any help.

解决方案

Try linq to xml?

Dim partNos = _
    From item In purchaseOrder...<Item> _
    Where (item.<Quantity>.Value * _
           item.<USPrice>.Value) > 100 _
    Order By item.<PartNumber>.Value _
    Select item


I copyed this code from MSDN.For further knowledge.Refer to http://msdn.microsoft.com/en-us/library/bb387061.aspx[^]


这篇关于如何在XML中查询解决方案中的临时表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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