I have a DataSet MediaDataSet1 that has one table MediaList with 3 columns.
I also have a form that has 3 textboxes and 2 buttons. One button to add the data input from the text boxes. One to output the data in the DataSet to XML. However the output never contains the data. I am not sure what is wrong. Below is the code in it's current state. Any help would be appreciated.
private void button1_Click(object sender, EventArgs e)
{
MediaDataSet1 mDS = new MediaDataSet1();
//DataTable mDT = mDS.Tables["MediaList"];
DataRow mDR = mDS.Tables["MediaList"].NewRow();
mDR["MediaName"] = MediaNameTB.Text;
mDR["MediaType"] = MediaTypeTB.Text;
mDR["MediaLength"] = MediaLengthTB.Text;
mDS.Tables["MediaList"].Rows.Add(mDR);
//mDT.Rows.Add(mDR);
//mDS.AcceptChanges();
}
private void button2_Click(object sender, EventArgs e)
{
MediaDataSet1 mDS = new MediaDataSet1();
mDS.WriteXml("C:\\Documents and Settings\\user003\\My Documents\\testOut.xml");
}
The XML output always only contains this.
Many Thanks.
Jeremy
Jeremy FourmanPosted Jun 15, 2008, 4:51 PM
Edit: Right now I am loading XML and rewriting with new entries to load on next media addition, this seems to be a heavy sort of action, what would be a better way?
Thank you .
Jeremy
Bechir BejaouiPosted Jun 15, 2008, 4:19 PM
{
MediaDataSet1 mDS = new MediaDataSet1();
//DataTable mDT = mDS.Tables["MediaList"];
DataRow mDR = mDS.Tables["MediaList"].NewRow();
mDR["MediaName"] = MediaNameTB.Text;
mDR["MediaType"] = MediaTypeTB.Text;
mDR["MediaLength"] = MediaLengthTB.Text;
mDS.Tables["MediaList"].Rows.Add(mDR);
//mDT.Rows.Add(mDR);
//mDS.AcceptChanges();
}
private void button2_Click(object sender, EventArgs e)
{
OK my freind the problem is here I mean the line bellow
when you use
MediaDataSet1 mDS = new MediaDataSet1();
That means that you define a new blanc dataset and you load it
mDS.WriteXml("C:\\Documents and Settings\\user003\\My Documents\\testOut.xml");
}
The XML output always only contains this.
to avoid such trouble try this instead:
MediaDataSet1 mDS;
private void button1_Click(object sender, EventArgs e)
{
mDS = new MediaDataSet1();
//DataTable mDT = mDS.Tables["MediaList"];
DataRow mDR = mDS.Tables["MediaList"].NewRow();
mDR["MediaName"] = MediaNameTB.Text;
mDR["MediaType"] = MediaTypeTB.Text;
mDR["MediaLength"] = MediaLengthTB.Text;
mDS.Tables["MediaList"].Rows.Add(mDR);
//mDT.Rows.Add(mDR);
//mDS.AcceptChanges();
}
private void button2_Click(object sender, EventArgs e)
{
mDS.WriteXml("C:\\Documents and Settings\\user003\\My Documents\\testOut.xml");
}