Appending dataset values to xml file

Appending dataset values to xml file

Different dataset values can be appended to a single xml file. This can be done as follows. First write the dataset values to  StringWriter  and then save the stringwriter to xml file.

            DataTable tab1 = new DataTable();
            tab1.Columns.Add(”name”);
            DataRow dr = tab1.NewRow();
            dr[”name”] = “aa”;
            tab1.Rows.Add(dr);

            DataTable tab2 = new DataTable();
            tab2.Columns.Add(”name”);
            DataRow dr2 = tab2.NewRow();
            dr2[”name”] = “aa”;
            tab2.Rows.Add(dr2);

            DataSet ds1 = new DataSet();
            ds1.Tables.Add(tab1);

            DataSet ds2 = new DataSet();
            ds2.Tables.Add(tab2);

            StringWriter sw = new StringWriter();

            ds1.WriteXml(sw);
            ds2.WriteXml(sw);

           string tosave =” ” + sw.ToString()+”";

           // write the tosave to file.

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.