Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I want to be able to save the data from datagridview when form closes. And then load the data when the form is opened again.

I tried to do this with an sqlite database. But the DLL's were diving me a problem. And i dont know how to embed the .3db file.

Is there a better/ easier way to do this?


thanks

nicole
Posted

1 solution

You don't want to change an embedded file if you can possibly avoid it: it means altering an executable file which is the kind of activity that virus checkers do look for...
Instead, store the info in a standard external file (see here for suggestions as to where to store it: Where should I store my data?[^])

An SqLite DB should work ok, but if you want to just save and restore the data via a DataTable, then the DataSet has methods to read and write XML files directly:
Easy write:
Create your data in a DataTable, then:
C#
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.WriteXml(@"D:\Temp\td.xml");


Easy Read:
C#
DataSet ds = new DataSet();
ds.ReadXml(@"D:\Temp\td.xml");
dt = ds.Tables[0];


You can use DataTable.ReadXml instead, but it doesn't support schema inference, DataSet.ReadXml does.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900