2
Answers

Newbie C# - DataSet AddRow (Solved)

Jeremy Fourman

Jeremy Fourman

16y
5.8k
1
Hello. Fairly new to C# and the DataSet concept.
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.

<?xml version="1.0" standalone="yes"?>
<MediaDataSet1 xmlns="http://tempuri.org/MediaDataSet1.xsd" />

Many Thanks.
Jeremy
Answers (2)