>I am retrieving an ArrayList from a third party .NET web service, and trying to display some of the results on an ASP.NET web page. In fact, I have already managed to get this far.
>
>However, the data is not in the order in which I want it. The data I am extracting contains a text value for each row, the last characters of which are a date in the format dd-mmm-yy. What I want to do is to read out those dates, and sort the list in reverse date order (ie newest first), and then display that list on my web page.
>
>Now, in VFP I could do that in two seconds flat. However, this is c#...
>
>Help please.
>
>TIA, Kevin
Kevin,
Generally I prefer it to serialize it back into an XML and create a dataset that I can manipulate easier. If I'm sure what I'd get is simply representable by a table than create a datatable.
ie: Get web service result into a dataset
XmlSerializer xs = new XmlSerializer(typeof(myWebService.myClass));
MemoryStream ms = new MemoryStream();
TextWriter writer = new StreamWriter(ms);
xs.Serialize(writer, wr);
ms.Seek(0,SeekOrigin.Begin);
DataSet ds = new DataSet("MyDataSet");
ds.ReadXml(ms,XmlReadMode.Auto);
Get an array of rows into a datatable:
myWS.myType[] rows = webservice.someGetMethod("parameter");
DataTable dt = new DataTable("myData");
System.Reflection.FieldInfo[] fi = rows[0].GetType().GetFields();
for(int i=0; i<fi.Length;i++)
{
dt.Columns.Add(fi[i].Name,fi[i].FieldType).AllowDBNull = true ;
}
foreach(myWS.myType rw in rows)
{
DataRow dr = dt.NewRow();
for(int i=0; i<fi.Length;i++)
{
dr[i] = fi[i].GetValue(rw);
}
dt.Rows.Add(dr);
}
PS: There should be much easier ways but I don't know yet.
Cetin