Here is my current issue. I need to display a tree like structure displaying a recall roster. Our DBA created a stored procedure that returns [level],[name],[contact_info].
Example looks like:
[1] [test name1] [contact info]
[2] [sub to1] [contact info]
[3] [sub to2] [contact info]
[4] [sub to3] [contact info]
[3] [sub to2] [contact info]
[2] [sub to1] [contact info]
etc…
It’s sorted in the order of the hierarchy
I haven’t really worked with XML much but is that the way to go in loading/presenting this data. Currently when I retrieving the data I’m returning it in a datatable. There may also be a need to export this data to Excel.
Can anyone point me a good direction to go with this?
1) Do not trust in ANY data result order that you cannot stablish and manipulate. The “standar” way to retrieve data from a stored procedure is a datareader, datatable or dataset. You can even user Entity Framework to encapsulate the data. None of them ensures that the order is preserved. Assuming your resultset will be ordered is too risky.
2) Ask your DBA to include hierarchy informaion in the result (for example, a field with the key of the parent record)
3) Recursion works well for Hierarchy problems. Design your algorithm to start with a xml node and a bunch of top-level records. For each record: add a new xmlnode and make a recursive call passing the children of the record you just added.
4) If the expected result is small (lets say, a few hundreds of records) you can get all the data, store it in a datatable and use the Filter property to search for specific records. If the expected result is several thousand records, ask your DBA to create a store procedure to read one record’s children and make a call to such procedure for each record in the xml node. Make sure you don’t have loops in the data 🙂