Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / October 2006

Tip: Looking for answers? Try searching our database.

Dataset and Nested Class???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LW - 22 Oct 2006 05:34 GMT
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;
   }

Any help, hints or suggestions welcome!

Laura
Mark Nelson - 23 Oct 2006 13:48 GMT
LW,

You don't need nested class, but you can achieve it with nested custom
collection.
This is the easier way to hit this problem.
OrderInfo>
   <CustomerID>VINET</CustomerID>
   <OrderID>10248</OrderID>
   <Dates>
       <OrderDate>07/07/1996</OrderDate>
       <ShippedDate>08/08/1996</ShippedDate>
   </Dates>
</OrderInfo>

Represent the class in the following format
<Serializable>_
public class OrderInfo

public property CustomerID as String
public property OrderId as Integer
public property DataCol as OrderShipDataCollection
End Class

The collection or OrderShipData will have the following defintion
Public Class OrderShipDate
Public property OrdShpDate as Date
Public property DateType as Integer

End Class

If you go by leveraging Custom Collection you don't need to worry about
tweaking the serialization framework of .NET

Signature

Thanks & Regards,
Mark Nelson

> Hi!
> I have a DataSet and a class in my Web Service.
[quoted text clipped - 69 lines]
>
> Laura
LW - 23 Oct 2006 16:00 GMT
Mark -
Thanks for your email. I did not quite understand your email being new to
C# and .NET in general. Can you explain some more ? I am not sure how
serialization works in this example and also how my XML output will still
be grouped.

Thanks,
LW

> LW,
>
[quoted text clipped - 102 lines]
> >
> > Laura
LW - 24 Oct 2006 06:27 GMT
Can Mark or some other kind soul please reply to my original post ?
Please??????

Thanks,
LW

> Mark -
> Thanks for your email. I did not quite understand your email being new to
[quoted text clipped - 4 lines]
> Thanks,
> LW
LW - 25 Oct 2006 06:59 GMT
John Saunders in another group answered my question. Thanks John!

LW

> Can Mark or some other kind soul please reply to my original post ?
> Please??????
>
> Thanks,
> LW

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.