Question : dataset to xml

hi -- i've now spent way too much time trying to figure out how to make this work. i'm using vs2010 and c#. i had an expectation that if i populate a dataset from an xml file -- and specified the schema -- that the data set would write back new rows in hte same place (ie the same node = table equivalence) as it took it from. For example, if i read an xml file with the following data:
 <modules>
      <eachModule>
        <moduleType>NNP Control Tower</moduleType>
        <moduleName>Control</moduleName>
        <pathLetter>T</pathLetter>
        <nodeNumber>8</nodeNumber>
        <revision>1.0</revision>
        <subNetNumber>1</subNetNumber>
        <moduleRecordID>10</moduleRecordID>
      </eachModule>
      <eachModule>
        <moduleType>NNP Master Test</moduleType>
        <moduleName>test</moduleName>
        <pathLetter>R</pathLetter>
        <nodeNumber>1</nodeNumber>
        <revision>1.0</revision>
        <subNetNumber>1</subNetNumber>
        <moduleRecordID>20</moduleRecordID>
      </eachModule>
    </modules>
this can be used to populate a table from DataTable dtMod = ds.Tables["eachModule"]. the table is then used to populate a gridview. i can then manipulate the table via the gridview to add rows. when i go to save the applicaiton, i use ds.writeXML(myfile) back to the file i originally opened. this works -- and the next time i open it the table and gridview are correctly populated. however the new row is appened at the top level of xml file, rather than being appended at the appropriate spot in the schema (ie modules > each module).

what i want to know is whether this is the way the system works and if i want to append a new row to a table, i have to know that and write to a node in the xml file explicitly.
thanks,
Jim

Answer : dataset to xml

Hi,

I think I see what is going on.  You are not setting the "generate column" modules_Id.

See below:


private void add_PB_Click(object sender, EventArgs e)
        {

            try
            {
                //Assume DataSet is call ds.
                DataRow parent = ds.Tables["modules"].Rows[0]; //Should do some checking here to see if row exists
                int maxValue = 0;
                DataRow dr = dtMod.NewRow();
                   
               //Set parent row!!!
               dr["modules_Id"] = parent["modules_Id"];
               

                if (dtMod.Rows.Count != 0)
                {
                    foreach (DataRow row in dtMod.Rows)
                    {
                        if (Convert.ToInt16(row["moduleRecordID"]) > maxValue)
                            maxValue = Convert.ToInt16(row["moduleRecordID"]);
                    }
                }
           
                dr["pathLetter"] = "R";
                dr["nodeNumber"] = "1";
                dr["subNetNumber"] = "1";
                dr["moduleRecordID"] = maxValue + 5;

                dtMod.Rows.Add(dr);

                mainForm.isDirty = true;
            }
            catch (SystemException err)
            {
                MessageBox.Show(err.Message);
            }

        }
Random Solutions  
 
programming4us programming4us