我应该如何最好地从 VB.net 查询我的数据集?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/749448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:09:58  来源:igfitidea点击:

How should I best query my dataset from VB.net?

vb.netdataset

提问by Andrew Parsons

I have a VB.Net data set that contains data from multiple tables. Does anyone have any good suggestions on how to query data out of the dataset. I want to run SQL-like queries on a dataset to extract data that fits a certain "where" statement.

我有一个 VB.Net 数据集,其中包含来自多个表的数据。有没有人对如何从数据集中查询数据有什么好的建议。我想在数据集上运行类似 SQL 的查询以提取适合某个“ where”语句的数据。

回答by TheTXI

Use the DataTable.Select()method.

使用DataTable.Select()方法。

Here is some information from the official MSDN documentation.

以下是来自官方MSDN 文档的一些信息。

As said in later posts, Linq is another possibility and will probably give you much more versatility, which you may not need depending upon your own requirements.

正如在后面的帖子中所说,Linq 是另一种可能性,它可能会给你更多的多功能性,你可能不需要,这取决于你自己的要求。

回答by Jon Skeet

If you're using .NET 3.5, you can use LINQ to DataSet.

如果您使用 .NET 3.5,则可以使用LINQ to DataSet

Basically you use DataTableExtensions.AsEnumerable(an extension method) to access the rows as an IEnumerable<DataRow>and then you can use normal LINQ to Object operators. The DataRowExtensionsextensions make this simpler.

基本上你使用DataTableExtensions.AsEnumerable(一种扩展方法)来访问行IEnumerable<DataRow>,然后你可以使用普通的 LINQ to Object 运算符。该DataRowExtensions扩展使得这个简单。

If you're using a strongly typed DataSet, the queries look even better.

如果您使用强类型DataSet,查询看起来会更好。

I prefer this option over DataTable.Select- all that messing about with escaping, formatting string queries etc feels like a real backward step.

我更喜欢这个选项DataTable.Select- 所有与转义、格式化字符串查询等有关的东西都感觉像是真正的倒退。

回答by Pedro

You should try using Linq.

您应该尝试使用 Linq。

It will provide you lots of features regarding querying your objects.

它将为您提供许多有关查询对象的功能。

try getting more information here: http://msdn.microsoft.com/en-us/netframework/aa904594.aspx

尝试在此处获取更多信息:http: //msdn.microsoft.com/en-us/netframework/aa904594.aspx

Or google for Linq to DataSets

或者谷歌搜索 Linq to DataSets