Dataset and Nested Class???

G

Guest

Hi!
I have a DataSet and a class in my Web Service.

My output for example is:

<OrderInfo>
<CustomerID>VINET</CustomerID>
<OrderID>10248</OrderID>
<OrderDate>07/07/1996</OrderDate>
<ShippedDate>08/08/1996</ShippedDate>
</OrderInfo>

I would like it to be:
<OrderInfo>
<CustomerID>VINET</CustomerID>
<OrderID>10248</OrderID>
<Dates>
<OrderDate>07/07/1996</OrderDate>
<ShippedDate>08/08/1996</ShippedDate>
</Dates>
</OrderInfo>

What I am trying to do is group certain columns from my DataSet so
my XML output is like the one above. I was wondering if using
nested classes would be the way to go but have tried a few things
but none have worked. I tried to declare dates as an inner class but
got confused due to it being an array etc. Can anyone please help?
My code is as follows:

// the class looks like the following
public class OrderInfo {
public string CustomerID;
public int OrderID;
public DateTime OrderDate;
public DateTime ShippedDate;

public class OrderInfo() {}


}

[WebMethod]
public OrderInfo[] GetCustomersOrdersInfo(string custID, int year)
{

//Get the data
DataSet _data = GetCustomersOrders(custID, year);

DataRowCollection _rows = _data.Tables[0].Rows;

// Allocate the array
OrderInfo[] info = new OrderInfo[_rows.Count];

// Fill the array
int i=0;
foreach(DataRow _row in _rows)
{
OrderInfo o = new OrderInfo();
o.CustomerID = _row["CustomerID"].ToString();
o.OrderID = Convert.ToInt32(_row["OrderID"]);
o.OrderDate = DateTime.Parse(_row["OrderDate"].ToString());
o.ShippedDate =
DateTime.Parse(_row["ShippedDate"].ToString());

info[i++] = o;
}

return info;
}
 
G

Guest

Hi LW,

I'm aware of a way to achieve the following

<OrderInfo>
<CustomerID>VINET</CustomerID>
<OrderID>10248</OrderID>
<Dates>
<OrderDate>07/07/1996</OrderDate>
<ShippedDate>08/08/1996</ShippedDate>
</Dates>
</OrderInfo>
Instead of nested class, you could have it as Custom Collection property of
the class. Please have Dates as the cutsom collection of the OrderInfo class,
it should work fine for you.

Pls let me know if you need more details.
Thanks & Regards,
Mark Nelson
 
G

Guest

Mark -
I am not sure how I can use CustomCollection for achieve my XML output.
Can you provide a few more details please? I am using C#.

Thanks,
LW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top