473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Dataset and Nested Class???

LW
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
Oct 22 '06 #1
4 1663
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

--
Thanks & Regards,
Mark Nelson
"LW" wrote:
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
Oct 23 '06 #2
LW
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
"Mark Nelson" wrote:
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

--
Thanks & Regards,
Mark Nelson
"LW" wrote:
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
Oct 23 '06 #3
LW
Can Mark or some other kind soul please reply to my original post ?
Please??????

Thanks,
LW

"LW" wrote:
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
Oct 24 '06 #4
LW
John Saunders in another group answered my question. Thanks John!

LW
"LW" wrote:
Can Mark or some other kind soul please reply to my original post ?
Please??????

Thanks,
LW
Oct 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eric Decker | last post by:
With framework 1.0 the dataset.getxml() method returned the children nested within the parent. This doesn't seem to function this way with 1.1. Is there something I'm missing?
0
by: José Joye | last post by:
I have used the wizard of VisualStudio to generate a DataSet (typed dataSet). I need to have the structure serialized in XML in a nested way and not in a table representation e.g: I have 3...
2
by: James Ankrom | last post by:
Why does this fail? Dim relResources As New Data.DataRelation("Application_Resources", ..Tables("User_Applications").Columns("Application_id"),...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
0
by: Steve | last post by:
I have a dataset. I fill it with two recordsets from SQL queries. Tables are called tblPlanFYSpendingStage, tblSpendingStage.
0
by: George Durzi | last post by:
I have a DataSet with 3 tables, and two DataRelations dsSubs.Tables.TableName = "Subscriptions" dsSubs.Tables.TableName = "AccountManagers" dsSubs.Relations.Add "AccountManagers_Subscriptions",...
2
by: Joe | last post by:
Hi I have a typed dataset and I want to add a method to modify a value in the datarow. I want to inherit from the class so if the XSDchanges I would lose my code when the class regenerates ...
7
by: SteveT | last post by:
Can someone point me in the right direction? Somewhere I read that you reference a strongly typed dataset as if it were a class structure. For example, <SomeTests> <TestsGroups> <Group>...
3
by: leviwatts | last post by:
Exception Details: System.ArgumentException: DataTable already belongs to another DataSet. Googling for this error shows several post of people trying to manipulate a table within a dataset. Others...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.