Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello guys, please how do i save all the data in a dataGridView such that when i close and rerun the program, these data are not lost? thanks
Posted
Comments
[no name] 10-Aug-15 14:33pm    
elaborate more on your scenario? If you want to persist the data you can save it to DB and bind it again when your page is loading in browser.

You wouldn't normally do that - you would save and restore the underlying DataTable or similar instead. Think about it: do you normally save a CheckBox, or the bool Checked state which is the info you are interested in?

Have a look here: Google "serialize datatable c# site:codeproject.com"[^] - there are loads of examples of how to do it on this site alone!
 
Share this answer
 
This is called "persistence": https://en.wikipedia.org/wiki/Persistence_%28computer_science%29[^].

Basically, when your terminate your program somehow, your data is lost. The data is stored on RAM, which is reused later by the code and data of other applications. Note that not all OS work this way. Some of the persistent OS always store the whole state machines, and all applications, when restarted, get the same data as before termination, and this data is stored permanently, until the application discards it explicitly. As you are using C#, chances are, the system you are using is not like that.

You need to save your data in some database, or serialize and store in a file or some other stream, to restore it back later. Relational databases are usually used in .NET via ADO.NET, and the streams-based persistence is organized through serialization. Please see:
https://en.wikipedia.org/wiki/ADO.NET[^],
https://msdn.microsoft.com/en-us/library/aa286484.aspx[^],
https://en.wikipedia.org/wiki/Serialization[^],
https://msdn.microsoft.com/en-us/library/7ay27kt9%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^] (please read this part thoroughly, this is the fundamentally important serialization technology).

—SA
 
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