什么是基于C#
中的少量oracle查询构建xml文档的最佳方法从订单中选择orderID,qty,orderDate,deliveryDate
<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>
请咨询
答案 0 :(得分:1)
您可以使用XElement。
代码示例:
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 :(得分:0)
请参阅此示例:http://support.microsoft.com/kb/301271
除了SqlConnection&amp; SqlDataAdapter,使用OracleConnection&amp; OracleDataAdapter
答案 2 :(得分:0)