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(); >} >>
>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(); >} >