I have the following nested level XML file which I want to store in sql2005 database by C# :
Lot 1
]]>
LOT LOT 1
]]>
Lot 1
]]>
LOT LOT 1
]]>
Lot 2
]]>
LOT LOT 2
]]>
Lot 2
]]>
LOT LOT 2
]]>
I wrote the code like this:
using (SqlConnection conn = new SqlConnection(connectionInfo))
{
// Try with sql bulk copy
DataSet ds = new DataSet();
StringBuilder s = new StringBuilder();
s.Append("\n");
s.Append("
s.Append("
s.Append("
s.Append("
s.Append("
s.Append("
s.Append("
s.Append("
s.Append("
s.Append("\n");
s.Append(" \n");
s.Append("
s.Append("\n");
s.Append(" \n");
s.Append("
s.Append("\n");
s.Append(" \n");
s.Append("
s.Append("\n");
s.Append(" \n");
s.Append("
s.Append("");
s.Append("");
String xmlString = s.ToString();
// Create an XmlReader
XmlReader reader = XmlReader.Create(new StringReader(xmlString));
ds.ReadXml(reader);
BUT it is filling only top 3 level node of data ID , AUCTION_ID , INVENTORY_ID …not the nested level data
SqlConnection connection = new SqlConnection(connectionInfo);
SqlBulkCopy sbc = new SqlBulkCopy(connection);
sbc.DestinationTableName = "BidInventory";
connection.Open();
//table 0 is the main table in this dataset
sbc.WriteToServer(ds.Tables[0]);
connection.Close();
I tried to pass the file with full path like ds.ReadXml(("C:\\AuctionNetwork\\Message.xml");
But the result is the same…
Can you please guide me how can I the whole xml data in my dataset or is there any other way of doing it.
Please help
Replies
Know the answer? Post it — somebody with the same question will find it here.