Windows Develop Bookmark and Share   
 index > Windows Forms General > save a System.Data.DataTable into Properties.Settings and persist throughout application
 

save a System.Data.DataTable into Properties.Settings and persist throughout application

I use vs2008 C#
at run time I want to be able to save a datatable into properties.Settings so that it can persist throughout my application, then all forms can retrieve the same data from this datatable. How can I achieve this?

thanks in advance!

Achievement provides the ultimate pleasure in life
  • Edited byssfftt Friday, October 02, 2009 6:58 PM
  •  
ssfftt  Friday, October 02, 2009 6:37 PM
You stated that you want persistence through the lifetime of your application. That does not requires Properties.Settings which is for persistence between application instances (i.e. persisted to disk).

All you need to do is create a singleton or static class to hold the DataTable.

public static class Globals
{
    public static DataTable MyTable;
}

Globals.MyTable can be accessed anywhere in your application. Where you load it is up to you. You might do it in Main for instance.

static void Main()
{
    Globals.MyTable = new DataTable();
    ... // fill the table
}
  • Marked As Answer byssfftt Saturday, October 03, 2009 7:48 PM
  •  
Tergiver  Saturday, October 03, 2009 7:45 PM
Data Table's serialization is not documented and could change between versions. Why not just use a simple array?

The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP
Sheng Jiang 蒋晟  Friday, October 02, 2009 6:56 PM
thanks for your quick reply. did you mean using a 2 dimensional array?
Achievement provides the ultimate pleasure in life
ssfftt  Friday, October 02, 2009 6:59 PM
Not sure what is your actual data structure. DataTable isn't a 2D array. 
You can use any XML-serializable type.


The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP
Sheng Jiang 蒋晟  Friday, October 02, 2009 7:31 PM
sorry for asking silly questions, but what are the XML-serializable types and which particular one is most suitable for my case?
Achievement provides the ultimate pleasure in life
ssfftt  Saturday, October 03, 2009 10:30 AM
types that mark itself as serializable. Take a look at ASMX and XmlSerialization forum for details.
There isn't one. If you have a multiple dimensional array, I suggest you declare a  serializable collection type whose elements are serializable collections.


The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP
Sheng Jiang 蒋晟  Saturday, October 03, 2009 12:57 PM
You stated that you want persistence through the lifetime of your application. That does not requires Properties.Settings which is for persistence between application instances (i.e. persisted to disk).

All you need to do is create a singleton or static class to hold the DataTable.

public static class Globals
{
    public static DataTable MyTable;
}

Globals.MyTable can be accessed anywhere in your application. Where you load it is up to you. You might do it in Main for instance.

static void Main()
{
    Globals.MyTable = new DataTable();
    ... // fill the table
}
  • Marked As Answer byssfftt Saturday, October 03, 2009 7:48 PM
  •  
Tergiver  Saturday, October 03, 2009 7:45 PM

You can use google to search for other answers

Custom Search

More Threads

• how to get access to form's property from a method in different project?
• Column Selection
• WM_QUERYENDSESSION and differences between Win2000 & 2003
• Mouse events for entire form
• "Alt+TAB" Form Problem
• How to use Fillpath?
• How do I display top part of a panel
• how to make valdation to my input data
• open a new window using javascript
• Windows Schedular??