locked
Saving & Opening Data of Windows form in a File RRS feed

  • Question

  • Hello everyone !

    First of all i am kinda new to C# programming, so i hope this is not taken as a fail question in C# forums.

    I'm having a difficult time trying to figure out my Windows Form Application.

    At the moment my Windows Form Application contains various containers, menus and common controls like check boxes,  I'm also including a DatagridView element and a small DataTable.

    What i am trying to do is simple, in mind, but i haven't been able to make it work.

    This are the simple steps of what i am trying to achieve:

    1. Run my Windows Form Application.
    2. Input some data into the DataTable, change some values in rows, check & uncheck some text boxes, etc. 
    3. Click the File Save button, save a file with the information and close the application. 
    4. Run my application and Open the file i just saved, read the file and display the information of my DataTable, checkboxes, textFields, etc.

    And that's about it. I'm not planning to implement a database or something, i just want to be able to save my work in my Application and open it later.

    I've read about SaveFile and OpenFile Dialogs, but actually i'm not sure how can i manage the part where by some programming functions i save a file with the information in my Application and interpret the file to update the data.

    Specifically, How can i program a function that saves a file with the data on my DataTable?, i mean saving them as a string, or as numbers that i'll interpret when i open the file. I am confused about it.

    Thanks


    Isaac
    Wednesday, December 8, 2010 11:18 PM

Answers

  • The DataTable class has (several overloaded) WriteXml and ReadXml methods, that you could use to serialise the data to/from a file.
    --pogo (pat)
    • Proposed as answer by BonnieBMVP Thursday, December 9, 2010 2:23 AM
    • Marked as answer by Bin-ze Zhao Monday, December 13, 2010 6:41 AM
    Wednesday, December 8, 2010 11:39 PM

All replies

  • The DataTable class has (several overloaded) WriteXml and ReadXml methods, that you could use to serialise the data to/from a file.
    --pogo (pat)
    • Proposed as answer by BonnieBMVP Thursday, December 9, 2010 2:23 AM
    • Marked as answer by Bin-ze Zhao Monday, December 13, 2010 6:41 AM
    Wednesday, December 8, 2010 11:39 PM
  • You could also use the Settings object (look under your project properties, there is a tab called Settings where you can add one).

     

    You could also use a custom class and use a BinaryFormatter to serialize the data to disk.

    Friday, December 10, 2010 7:32 PM