Create XML document from oracle request in C #
What is the best way to generate XML document based on multiple oracle requests in C #
select orderID, qty, orderDate, deliveryDate from Orders
<orders>
<order>
<orderID>1</orderID>
<qty>10</qty>
<orderDate>22-Jan-2012</orderDate>
<deliveryDate>25-Jan-2012</deliveryDate>
</order>
<order>
<orderID>2</orderID>
<qty>10</qty>
<orderDate>22-Jan-2012</orderDate>
<deliveryDate>25-Jan-2012</deliveryDate>
</order>
</orders>
I ask for advice
+3
source to share
3 answers
You can use XElement.
Sample code:
using (SqlConnection con = new SqlConnection(ConnectionString))
{
con.Open();
using(SqlCommand command = new SqlCommand("select orderID,qty,orderDate,deliveryDate from Orders", con))
{
SqlDataReader reader = command.ExecuteReader();
XElement root = new XElement("Orders");
while(reader.Read())
{
root.AddFirst(
new XElement("Order",
from i in Enumerable.Range(0, reader.FieldCount)
select
new XElement(reader.GetName(i), reader.GetValue(i))
)
);
}
root.Save(Console.Out);
}
}
+1
source to share
Please refer to this example: http://support.microsoft.com/kb/301271
Use OracleConnection and OracleDataAdapter instead of SqlConnection and SqlDataAdapter .
0
source to share
You can do this in the oracle request itself. In the meantime, there is no need to know about it. ”
Please find the link below
https://forums.oracle.com/forums/thread.jspa?threadID=1034099
0
source to share