views:

318

answers:

3

I have a Dataset i want to apply a filter based on a dataset-type field record count, something like: 'NESTED_DATASET_FIELD.RecordCount > 0'

A: 

OnFilterRecord event

Adelf
Oh, sorry. I didn't understand all the question...
Adelf
+2  A: 

If the dataset comes from a SQL based storage engine, use a select distict query on the joined table with only fields from the master table in the result set. Let the SQL engine do the work for you.

Ritsaert Hornstra
The data cames from a XML File with three levels of table nesting. Thanks
Gedean Dias
If you parse the XML data yourself you might add an extra field ChildNodeCount to the master dataset and fill it while parsing and use OnFilterRecord to check if it is > 0. Either way: in the end it comes down to counting child records: by a SQL engine, a mster detail link, your own parser etc etc. Having the count in the master table will give you a speed advantage over filtering using record scanning in a detail dataset, but that will only be an issue if you have large amounts of data.
Ritsaert Hornstra
+1  A: 

Depending on your situation, you can use:

  1. In OnFilterRecord event you can have:

    Accept := myDataSetField.NestedDataSet.RecordCount>0;

  2. If you have a SQL backend you can use the Exists or Count in order to fetch only the records which you need. Perhaps is the best approach if you are over a network. However I don't know what infrastructure you have.

  3. In OnFilterRecord event you can have:

    Accept := not myDataSetField.IsNull; //Just testing if the DataSet field is empty - which is one of the fastest ways to do it ...but this depends on the structure of your data / dataset etc.

  4. Sometimes is better to have a dedicated field in your DataSet / Table to specify this status because usually getting such info from the nested dataset can be expensive. (One must fetch it at least partially etc.)

  5. Also, for the same considerations (see 4. above) perhaps you can have a Stored Procedure (if your DB backend permits) to get this info.

HTH