c# - Datatable is not being populated -
attempting populate datatable sqldatareader (i don't think can use dataadapter because of way parsing xml string). looking @ examples of datatables online should work, doesn't. when debug table {} when runs through while loop. what's deal?
string sqlentry = configurationmanager.connectionstrings["sqlpass"].connectionstring; sqlconnection conn = new sqlconnection(sqlentry); try { conn.open(); conn.changedatabase(configurationmanager.connectionstrings["db"].connectionstring); string sqlquery = "select * equipinspection"; sqlcommand sqlcomm = new sqlcommand(sqlquery, conn); sqldatareader myreader; myreader = sqlcomm.executereader(); datatable table = new datatable(); table.columns.add("equipment", typeof(string)); table.columns.add("serialno",typeof(string)); table.columns.add("contractor",typeof(string)); table.columns.add("date", typeof(string)); table.columns.add("deficiencies", typeof(string)); if (myreader.read()) { { string stringtosplit = myreader["formxml"].tostring(); string[] xmlinfo = stringtosplit.split(new string[] { ";ankr!" }, stringsplitoptions.none); datarow row = table.newrow(); row["equipment"] = xmlinfo[0]; row["serialno"] = xmlinfo[1]; row["contractor"] = myreader["name"].tostring(); row["date"] = myreader["date"].tostring(); row["deficiencies"] = xmlinfo[12]; table.rows.add(row); } while (myreader.read());
here sample of xml format. may way structured or way parsing it.
<!--equipment inspection form test--> <equipmentinspection date="2013/08/07" time="12:05 am" location="somewhere" contractorname="joe" operator="jane" position="boss" contact="2132213421"> <field id="txtequipment" type="textbox">jackhammer;ankr!</field> <field id="txtserial" type="textbox">1234a5a-1;ankr!</field> <field id="txtmanufacturer" type="textbox">test;ankr!</field> <field id="txtusage" type="textbox">test;ankr!</field> <field id="txtservice" type="textbox">2013/08/05;ankr!</field> <field id="rblrecentinspect" type="radiobuttonlist">no;ankr!</field> <cblshift>2, ;ankr!</cblshift> <cbldaysinspected>w, f, ;ankr!</cbldaysinspected> <field id="rbldamage" type="radiobuttonlist">yes;ankr!</field> <field id="txtdamage" type="textbox">;ankr!</field> <field id="txtrepairs" type="radiobuttonlist">no;ankr!</field> <field id="rbldef" type="radiobuttonlist">no;ankr!</field> <field id="txtdef" type="textbox">it broke;ankr!</field> </equipmentinspection>
are clicking spyglass @ actual table? quick glance seem doing right , if debugging isn't erroring out you're getting data fine. table isn't going have data until add row, of course. know sounds silly, make sure click spyglass after @ least 1 iteration of table.rows.add(row); ....
Comments
Post a Comment