MattyJim
04-09-2005, 02:20 PM
I have a C# assignment to complete, which requires me to ceate a userform and output the fields to XML.
The XML file is intended to act as a database, and all information should be updatable, deletable, etc, etc.
Everything works fine so far; I've managed to create the XML file and write a schema that can be updated with a new datacolumn every time the user clicks a particular button.
When I check the XML file, the datacolums have been added as required.
My main task now is to write datarows to the datacolumn, so that I could, for example, have a datacolumn that related to a particular person, and which held details in datarows about that particular person (name, address, etc).
I NEED THE XML FILE TO BE UPDATED WITH A NEW COLUMN AND ACCOMPANYING ROWS EVERY TIME THE USER CLICKS A BUTTON.
The fragment of code shown below adds datacolumns just fine, but when I check the XML file, the datarows are never there: -
(Everything here is held within a button_click event, by the way, and the datacolumn names come from textboxes on my form)
DataSet ds = new DataSet();
FileStream finschema = new FileStream(DirName + "//myDataFile.xml",
FileMode.Open, FileAccess.Read, FileShare.Read);
ds.ReadXmlSchema(finschema);
finschema.Close();
FileStream fout = new FileStream(DirName + "//myDataFile.xml",
FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
DataColumn newcolumn = new DataColumn("Column " + textBox1.Text);
ds.Tables[0].Columns.Add(newcolumn);
DataRow myRow;
myRow = ds.Tables[0].NewRow();
// Then add the new row to the collection.
myRow["Column " + textBox1.Text] = textBox2.Text;
ds.Tables[0].Rows.Add(myRow);
ds.WriteXmlSchema(fout);
fout.Close();
:confused: Any of you crazy computer geniuses out there got any ideas, coz I'm tearing my hair out at the minute!!! :confused:
Any help that you could offer would be greatly appreciated!!
Thanks,
Matt :)
The XML file is intended to act as a database, and all information should be updatable, deletable, etc, etc.
Everything works fine so far; I've managed to create the XML file and write a schema that can be updated with a new datacolumn every time the user clicks a particular button.
When I check the XML file, the datacolums have been added as required.
My main task now is to write datarows to the datacolumn, so that I could, for example, have a datacolumn that related to a particular person, and which held details in datarows about that particular person (name, address, etc).
I NEED THE XML FILE TO BE UPDATED WITH A NEW COLUMN AND ACCOMPANYING ROWS EVERY TIME THE USER CLICKS A BUTTON.
The fragment of code shown below adds datacolumns just fine, but when I check the XML file, the datarows are never there: -
(Everything here is held within a button_click event, by the way, and the datacolumn names come from textboxes on my form)
DataSet ds = new DataSet();
FileStream finschema = new FileStream(DirName + "//myDataFile.xml",
FileMode.Open, FileAccess.Read, FileShare.Read);
ds.ReadXmlSchema(finschema);
finschema.Close();
FileStream fout = new FileStream(DirName + "//myDataFile.xml",
FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
DataColumn newcolumn = new DataColumn("Column " + textBox1.Text);
ds.Tables[0].Columns.Add(newcolumn);
DataRow myRow;
myRow = ds.Tables[0].NewRow();
// Then add the new row to the collection.
myRow["Column " + textBox1.Text] = textBox2.Text;
ds.Tables[0].Rows.Add(myRow);
ds.WriteXmlSchema(fout);
fout.Close();
:confused: Any of you crazy computer geniuses out there got any ideas, coz I'm tearing my hair out at the minute!!! :confused:
Any help that you could offer would be greatly appreciated!!
Thanks,
Matt :)