c# - Blank form when running the application -
i trying run application read xml file , displaying in form. however, keeps giving me blank form without data. how display order data?
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; using system.xml; namespace readorder { public partial class form1 : form { public form1() { initializecomponent(); } private void form1_load(object sender, eventargs e) { stringbuilder orderlist = new stringbuilder(); orderlist.append("order list:").append(environment.newline); int counter = 0; // location of xml file string xmlfilepath = @"..\..\orders.xml"; { // reference xmlreader object xmlreader reader = xmlreader.create(xmlfilepath); while (reader.readtofollowing("order")) { counter++; orderlist.append("order counter: " + counter + environment.newline); reader.readtofollowing("item"); int itemcount = 1; orderlist.append("item: " + itemcount + reader.readelementcontentasstring() + environment.newline); while (reader.readtonextsibling("item")) { itemcount++; orderlist.append("item: " + itemcount + reader.readelementcontentasstring() + environment.newline); } reader.readendelement(); } reader.close(); console.writeline(orderlist); console.read(); } } } } <?xml version="1.0" encoding="utf-8" ?> <orders> <order orderid="1"> <orderdate>28/5/16</orderdate> <buyerid>2</buyerid> <item> <itemid>100</itemid> <itemname>memory card</itemname> <description>300gb</description> <quantities>1</quantities> <unitprice>50.00</unitprice> <remarks>nil</remarks> </item> </order> <order orderid="2"> <orderdate>28/5/16</orderdate> <buyerid>4</buyerid> <item> <itemid>101</itemid> <itemname>samsung s6</itemname> <description>black</description> <quantities>1</quantities> <unitprice>700.00</unitprice> <remarks>nil</remarks> </item> </order> <order orderid="3"> <orderdate>28/5/16</orderdate> <buyerid>6</buyerid> <item> <itemid>102</itemid> <itemname>samsung s7</itemname> <description>gold</description> <quantities>1</quantities> <unitprice>899.00</unitprice> <remarks>nil</remarks> </item> </order> </orders>
you missed catch block. every try block,need implement catch block.
try { } catch(exception) { }
Comments
Post a Comment