| |

VerySource

 Forgot password?
 Register
Search
View: 612|Reply: 3

DataSet returns XML through web service. Can two tables be nested?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-18 19:00:01
| Show all posts |Read mode
As shown in the following code:
------------------------------
// The web service method returns an XmlDataDocument object
public XmlDataDocument TDBinding (string strHostcustid / * user input customer number * /)
{
DataSet ds = new DataSet ();
XmlDataDocument xd;
DataColumn parentCol;
DataColumn childCol;
// Two tables for accessing the database through ODBC, one is the main table and the other is the detailed table
OdbcConnection con = new OdbcConnection ("DSN = 137");
OdbcDataAdapter daCust = new OdbcDataAdapter ("select * from PData1.T01_PARTY where Host_Cust_Id = '" + strHostcustid + "'", con);
OdbcDataAdapter daEvnt = new OdbcDataAdapter ("select * from PData1.t05_financial_event_hm where Host_Cust_Id = '" + strHostcustid + "'", con);
// Put two result sets into dataset after query and return
daCust.Fill (ds, "Customer");
daEvnt.Fill (ds, "Event");
xd = new XmlDataDocument (ds);
return xd;
}
The XML format returned by this method is as follows:
<NewDataSet>
<Customer>
...
</ Customer>
<Event>
...
</ Event>
<Event>
...
</ Event>
<Event>
...
</ Event>
</ NewDataSet>
Because a Customer will have multiple events, this looks very long. I hope that the above xml can be adjusted to the following format, which is to indent the result set of event one level further:
<NewDataSet>
<Customer>
...
</ Customer>
<CustomerEvent>
<Event>
...
</ Event>
<Event>
...
</ Event>
</ CustomerEvent>
</ NewDataSet>

Thank you.
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-25 11:00:01
| Show all posts
DataCollumn [] parent = new DataCollumn[1];
DataCollumn [] child = new DataCollumn[1];
parent[0] = ds.Tables("Customer").Columns("Host_Cust_Id")
child[1] = ds.Tables("Event").Columns("Host_Cust_Id")

// Create DataRelation.
DataRelation CustEventRel= New DataRelation("CustomersEvent", parentCols, childCols, true)
// set the event as the child element of the parent Customer
CustEventRel.Nested = true;
// Add the relation to the DataSet.
ds.Relations.Add(CustEventRel);
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-25 11:30:01
| Show all posts
Sorry for something wrong
DataCollumn [] parent = new DataCollumn[1];
DataCollumn [] child = new DataCollumn[1];
parent[0] = ds.Tables("Customer").Columns("Host_Cust_Id");
child[0] = ds.Tables("Event").Columns("Host_Cust_Id");

// Create DataRelation.
DataRelation CustEventRel = New DataRelation("CustomersEvent", parent, child, true)
// set the event as the child element of the parent Customer
CustEventRel.Nested = true;
// Add the relation to the DataSet.
ds.Relations.Add(CustEventRel);
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-25 12:00:01
| Show all posts
// Create DataRelation.
DataRelation CustEventRel= New DataRelation("CustomersEvent",
ds.Tables["Customer"].Collumns["Host_Cust_Id"],
ds.Tables["Event"].Collumns["Host_Cust_Id"],
true);
// set the event as the child element of the parent Customer
CustEventRel.Nested = true;
// Add the relation to the DataSet.
ds.Relations.Add(CustEventRel);
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list