c# - Reading XML dynamic data in SQL Server -
i have xml column in table contains collection of data. every record may hold different collection type customers data , invoices data etc.
how can read cell & convert table in order bind data grid, collection times looks that
<arrayofreceipttransfer_receipt xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <receipttransfer_receipt> <receipttransfer_receipt_id>77491</receipttransfer_receipt_id> <receipttransferid>17839</receipttransferid> <receiptid>74080</receiptid> <amount>500.00</amount> </receipttransfer_receipt> </arrayofreceipttransfer_receipt>
and looks like
<arrayofinvoicebudgetitem xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <invoicebudgetitem> <invoiceid>21978</invoiceid> <budgetitemid>1473</budgetitemid> <amount>12</amount> </invoicebudgetitem> <invoicebudgetitem> <invoiceid>21978</invoiceid> <budgetitemid>1475</budgetitemid> <amount>11</amount> </invoicebudgetitem> </arrayofinvoicebudgetitem>
you have 1 root tag work
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.io; namespace windowsformsapplication1 { public partial class form1 : form { public form1() { initializecomponent(); string input = "<arrayofreceipttransfer_receipt xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlns:xsd=\"http://www.w3.org/2001/xmlschema\">" + "<receipttransfer_receipt>" + "<receipttransfer_receipt_id>77491</receipttransfer_receipt_id>" + "<receipttransferid>17839</receipttransferid>" + "<receiptid>74080</receiptid>" + "<amount>500.00</amount>" + "</receipttransfer_receipt>" + "</arrayofreceipttransfer_receipt>"; string xml = string.format("<?xml version=\"1.0\" encoding=\"utf-8\"?>{0}", input); stringreader reader = new stringreader(xml); dataset ds = new dataset(); ds.readxml(reader); datagridview1.datasource = ds.tables[0]; } } }
Comments
Post a Comment