Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Extract row-column from array of objects
Message
From
28/04/2011 15:16:30
 
 
To
28/04/2011 13:24:33
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
C# 4.0
Miscellaneous
Thread ID:
01508607
Message ID:
01508695
Views:
27
Thanks, Rob. This looks really juicy and I definitely would like to create a datatable so I am going to study your code carefully as this is new to me.

I did, however, finally plumb they mysteries of goldlasso.anyTypeArray. Looks pretty proprietary in functionality.

Here is the code that actually works so far :

Created this for testing - and also to examine the contents of the data on the back end. Definitely want to expand it.

Thanks everyone - I'm sure I'll be back after reading Paul's message ( which I must have missed on the last pass ) and trying Rob's datatable code
      public void RunQuery(string query, int limit, int offset, string filename)
        {
            anyTypeArray1[] result = null;
            result = this.Proxy.runQuery(query, limit, offset);
            if (result.Length > 0)
            {
                TextWriter twr = new StreamWriter(filename);

                twr.WriteLine("Limit " + limit.ToString() + "  " + query);
                twr.WriteLine(result.Length.ToString() + " records returned");
                int itemlength = result[0].item.Length;

                for (int i = 0; i < result.Length; i++)
                {
                    anyTypeArray1 rec = result[i];
                    string newline = "";
                    for (int j = 0; j < itemlength; j++)
                    {
                        string newstring = "";

                        if (rec.item.GetValue(j) == null)
                            newstring = "(null)";
                        else
                            newstring = rec.item.GetValue(j).ToString();

                        if (j < itemlength - 1)
                            newstring += ",";

                        newline += newstring;
                    }
                       twr.WriteLine(newline);
                }
                twr.Close();
            }
        }
>If you are looking to create a DataTable, the following might work:
>
>DataTable newTable = new DataTable();
>
>if (result.Any())
>{
>    // Assume all rows have the same structure, use the first to create the columns
>    var rowForColStructure = result.OfType<GLWebService.goldlasso.anyTypeArray1>().First();
>
>    // Create the structures with a generic name
>    DataColumn[] columns = rowForColStructure.item.Select((item, index) => new DataColumn(string.Format("Column{0}", index), item.GetType())).ToArray();
>    // Add the columns to the table                
>    newTable.Columns.AddRange(columns);
>    
>    // New rows get added when the query is executed via the ToList
>    var rows = result.OfType<GLWebService.goldlasso.anyTypeArray1>().Select(item => newTable.Rows.Add(item.item)).ToList();
>}
>
>
>The items would still be in their original types. If you need it as strings, change it to:
>
>DataTable newTable = new DataTable();
>
>if (result.Any())
>{
>    // Assume all rows have the same structure, use the first to create the columns
>    var rowForColStructure = result.OfType<GLWebService.goldlasso.anyTypeArray1>().First();
>
>    // Create the structures with a generic name
>    DataColumn[] columns = rowForColStructure.item.Select((item, index) => new DataColumn(string.Format("Column{0}", index), typeof(string))).ToArray();
>    // Add the columns to the table                
>    newTable.Columns.AddRange(columns);
>    
>    // New rows get added when the query is executed via the ToList
>    var rows = result.OfType<GLWebService.goldlasso.anyTypeArray1>().Select(item => newTable.Rows.Add(item.item)).ToList();
>}
>


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Previous
Reply
Map
View

Click here to load this message in the networking platform