yesterdaygaming at October 9th, 2009 09:24 — #1
Hello, now This is my code of form 1 (only got 1 form)
public partial class Form1 : Form
public DataTable Categories;
public DataTable Subcategories;
public DataColumn col1;
public DataColumn col2;
public DataColumn col3;
public DataColumn col4;
public DataColumn col5;
public DataSet Datacollection;
Datacollection = new DataSet("Alledata");
Categories = new DataTable();
Categories.TableName = "Categories";
col1 = Categories.Columns.Add();
col1.AllowDBNull = true;
col1.MaxLength = 5;
col1.ColumnName = "ID";
col2 = Categories.Columns.Add();
col2.AllowDBNull = true;
col2.MaxLength = 20;
col2.ColumnName = "Name";
col3 = Categories.Columns.Add();
col3.AllowDBNull = true;
col3.MaxLength = 100;
col3.ColumnName = "Description";
col4 = Categories.Columns.Add();
col4.AllowDBNull = true;
col4.MaxLength = 20;
col4.ColumnName = "Owner";
dataGridView1.DataSource = Categories;
This works for me. But if i compile the game, run it it doesn't save data if you enter. How can i save the data?
ddboarm at October 10th, 2009 01:27 — #2
Using just DataSet and DataTable, you do have the option of saving in 2 ways. The first, and easiest, involves saving the DataSet/DataTable to an XML format. I don't recall the method name off the top of my head. But check MSDN, it's there.
The second method for saving the data is to actually connect to an SQL datasource. It is a lot more involved...
alphadog at October 10th, 2009 08:59 — #3
Of course it doesn't automagically save the data! Where did you ask the computer to do so?
You have to realize computers are like highly literal idiot-savants. They can do lots of wonderous things very fast... as long as you explicitly tell them to do it.
In your case, nowhere do you instruct the computer to save the contents in the Dataset.
As ddboarm indicates, the question is how do you want to save the data? If you just want to save it to a file, then you have to code it out. Probably you wan to use the builtin WriteXml() (and ReadXml() to load it back in) functions. Google for some tuts.
Or, you might want to have different output, like a text file. Here's an example of how to do it.
If you want to save to a database, this gets more complicated.