views:

140

answers:

1

I have a C# web service that returns a DataSet with multiple DataTables. It's easy enough to get at the data using this web service event handler in Flex:

static public function getData_Handler(event:ResultEvent):void 
{
    for each(var table:Object in event.result.Tables)
    {
        // ...
    }
}

How can I access the name of each DataTable from Flex? When debugging, it's clear that each DataTable's name gets mapped to a property on the event.result.Tables object, but I don't see a programmatic way to get a string representation of the name.

A: 

I don't think they will be available separately in the result object. The best way to get them is to loop through an item of the result objects with a for...in loop and then read the column names from there.

Christophe Herreman
Unless I'm mis-reading this, it sounds like you're referring to obtaining column names for a table, which is exactly as you describe. I am asking about the names of the data tables themselves.
Alex Morris
The same goes for table names I suppose. If you can see them as properties of the Tables object in the debugger, you should be able to get them by looping through the properties with a for..in loop. What does the structure of the result object look like?
Christophe Herreman
There is actually a collection for column names further down the property chain. The result object is automatically transformed by Flex from the web service results into a DataSet-specific hierarchy of classes, and I'm unable to find a way to access the table list. Are you proposing a reflection solution to gather the names, since they are properties on the Tables object? It looks like that could work, so I'm exploring it now. Is there a way to use a for..in loop to access the list of properties on an object?
Alex Morris
Yes, if you use a for..in loop, it will loop over the property names of the object. A for each..in loop will loop over the property values.
Christophe Herreman
My apologies - I completely missed that the for..in function loops over dynamic properties. That is exactly what I was looking for. Now I wish I had the rep to vote this answer up...
Alex Morris