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.
views:
3176answers:
3Use the DataTable.Select()
method.
Here is some information from the official MSDN documentation.
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.
If you're using .NET 3.5, you can use 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 DataRowExtensions
extensions make this simpler.
If you're using a strongly typed DataSet
, the queries look even better.
I prefer this option over DataTable.Select
- all that messing about with escaping, formatting string queries etc feels like a real backward step.
You should try using 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
Or google for Linq to DataSets