c# - Windows Forms: Adding an empty DataTable to a Dataset -


i working on windows forms application in c# , have datagridview has data source datatable. datagridview , datatable loaded dataset stored on disk. if changes made in datagridview written out file when save button clicked. however, if rows deleted, next time program runs , try add row in datagridview, not written file since when load it, datatable not exist since rows deleted.

here code:

dataset ds = new dataset(); datatable dt160m = new datatable("dt160m"); datatable dt80m = new datatable("dt80m");  ds.readxml(filename);  dt160m = ds.tables["dt160m"]; dt80m = ds.tables["dt80m"];  datagridview160m.datasource = dt160m; datagridview80m.datasource = dt80m; 

now great. if delete records datagridview80m example, when reopen there no datatable called dt80m in dataset anymore. adding additional rows not create datatable.

any suggestions work around this? thanks.

the problem in point write dataset disk xml file. if 1 or both of datatable empty loose schema of table. fortunately there overload of dataset.writexml takes parameter.

ds.writexml(filename, xmlwritemode.writeschema); 

in way, resulting file on disk contains schema of tables if there no records.

of course, when read back, schema of tables using

ds.readxml(filename, xmlreadmove.readschema); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -