Gali Gali - 3 months ago 9
C# Question

how to run query on dataset?

I have a

DataSet
named
dsView
that contains data. Here is the code i use to read the XML:

dsView = new DataSet();
dsView.ReadXml(@"\c:MyXml.xml");


The data has a table named
MEN
with fields
Fname
and
Lname
. How do I run a query on this
dsView
? (for example:
select * from MEN where Fname = 'zz'
)

Answer

You cannot run complete SQL statements on a DataSet - but the DataTable inside your DataSet does have a method called Select(string) which selects an array of DataRow object that match a certain criteria.

Check out the MSDN docs on DataTable

You would probably have to do something like (untested):

DataTable tblMEN = dsView.Tables["MEN"];
DataRow[] results = tblMen.Select("Fname = 'zz'");
Comments