Click to See Complete Forum and Search --> : DataSets Question and Use


soph
August 9th, 2004, 01:46 PM
Hello All,

I am doing some research and trying to figure out the best method of storing and manipulating data for our project. I was considering using the .NET DataSets for creating my data structure, then storing the files in XML format. However, most of what I am reading is that DataSets are mostly used when an interface is needed between a database (such as SQL Server or Access). Is that correct?

Is there a way to just populate the DataSet, then put the data into an XML file without having to use a database? If yes, how can that be done? I created a complex type DataSet, but I am having a hard time figuring out how to populate and get it to create the resulting XML file for where the data will be stored.

Any help is appreciated.

Soph

markusd
August 10th, 2004, 02:44 AM
yes, it is definitely possible.

I've created some tools, using just DataSet's and saved the data to XML.

Here some hints to lookup in the NET Framework Help:


DataSet workSet = new DataSet("Cinema");
DataTable channelTable = new DataTable("Channels");
channelTable.Columns.Add("ID", typeof(int));
channelTable.PrimaryKey = new DataColumn[] {channelTable.Columns["ID"]};
channelTable.Columns.Add("ChannelName", typeof(String));
channelTable.Columns.Add("ChannelType", typeof(int));

workSet.Tables.Add(channelTable);

/* Relationship Movie-Channel */

DataColumn parentCol = workSet.Tables["Channels"].Columns["ID"];
DataColumn childCol = workSet.Tables["Movies"].Columns["Channel"];
// Create DataRelation.
relCustOrder = new DataRelation("MovieChannel", parentCol, childCol, false);
// Add the relation to the DataSet.

workSet.Relations.Add(relCustOrder);

// Add some Data...
DataRow rw = channelTable.NewRow()
rw["ID"] = 1;
rw["ChannelName"] = "test";
rw["ChannelType"] = 5;
channelTable.Rows.Add(rw);

// Save Data...
workSet.WriteXml(filename);


You can also create columns that are calculated values or values from other tables (parent<->child), the tricky part is then, when you save to XML to not save the "expression" based columns with it.

soph
August 10th, 2004, 10:13 AM
Thanks so much! I will give this a try!

Soph