c# - Can't update Xml file -


i'm trying update xml file using code.

int i; xmlnodelist list = xdoc.selectnodes("sale/saleslines/salesline");  foreach (xmlnode node in list) {     (i = 0; < count; i++)     {         node.selectsinglenode("vatamount").innertext = convert.tostring(datagridview.rows[i].cells[10].value);         xdoc.save(path);     }                     } 

so first of i'm trying update xml file using integer data grid. there 2 salesline nodes in xml file. above code update values in node sets both elements value last element read using loop. reads both(there 2 values read , updated in file) values updates last read value in both nodes vatamount element. btw count holds count of rows in grid. can me fix this. need solved.

ok. guys please forgive me. co-employee saw code , said not use code use this.

devexpress.xtragrid.views.grid.gridview view = (devexpress.xtragrid.views.grid.gridview)gridcontrol1.focusedview; view.posteditor(); view.refreshdata();  datatable table = ((dataview)gridview1.datasource).totable(); foreach (datarow dr in table.rows) {     //textbox8.text += convert.tostring(dr["newvatamt"]);     foreach (xmlnode node in list)     {         node.selectsinglenode("vatamount").innertext = convert.tostring(dr["newvatamt"]);     }     } xdoc.save(path); 

so i'm using dev express grid control instead of datagrid. , code i'm facing same problem. please go through code ad try suggest fix. please.

if understand correctly want need keep counter out of foreach loop (not loop inside loop). (notice should still check if rows[i] exists or exception).

int = 0; foreach (xmlnode node in list) {    node.selectsinglenode("vatamount").innertext = convert.tostring(datagridview.rows[i].cells[10].value);    i++; }  xdoc.save(path); 

also, want save document once after updated nodes.

update: second sample should follow similar pattern.

datatable table = ((dataview)gridview1.datasource).totable(); int = 0; foreach (xmlnode node in list) {     node.selectsinglenode("vatamount").innertext = convert.tostring(table.rows[i]["newvatamt"]);     i++;     } xdoc.save(path); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -