Trouble extracting and computing data from XML.

  • Thread starter Thread starter M K
  • Start date Start date
M

M K

I have an XML database I load into a typed dataset. I have
2 tables in this dataset. One has Orders, One has
customers. I want to do a query or computation that counts
orders based on Fields in the Orders and Customers table.
In a sql query I would do this:
SELECT Count(Orders.recNum) FROM Orders JOIN Customers
WHERE Orders.Field1 <> 'x' AND Customers.Type NOT 'Basic'

Something like that (I know the Join isn't correct). But I
want to do it on the dataset. How could I do that? I
already have a Relation between the two tables. (Tho I may
not have it set up correctly.)

Can somebody help me?
 
What you are looking for should be something similar to the code below.
Please check further information in the samples provided for
System.Data.DataTable.Select method. Notice that this method is overloaded
and there are different samples for each overloaded method. You can also
browse the samples .NET provides for DataSet manipulation.

string sSql = "Field1='y' AND Parent(Orders_TO_Customers).Type='Advanced' ";
DataRow[] arQualifiedRows = m_oDataSet.Tables["Orders"].Select(sSql);
int iCount = arQualifiedRows.Length;

Notice that Orders_TO_Customers is a relationship that you should have
created between these 2 tables in the dataset, before you query based on
this relationship.
Notice as well that I am using equal instead of different in the SQL string
because I forgot what the syntax is in DataSet select whenever you want
what's different (maybe it is <> , maybe it is != , etc.)
Notice that the Parent keyword only works well if Orders has a field (FK)
pointing to the Customers table.
Notice that I didn't compile the code above. My intention was to give you a
start point for you to do your own investigation. Anyway, all the code above
is based on experience with real dataset code (using DataTable.Select) I had
to develop recently.

Thanks.
Paulo

DISCLAIMER: This posting is provided "AS IS" with no warranties, and confers
no rights. Use of any possible included code samples are subject to the
terms specified at http://www.microsoft.com/info/cpyright.htm"
 
Back
Top