none
Convert Dataset to Xml with blank field in c# RRS feed

  • Question

  •  i want to convert Dataset to xml

      some tables in dataset contains blank record and when i create the xml (by using dataset.getxml())

    it creates xml but without the blanks records.. i want all records ...

    any suggestion ???

    • Moved by Eric Fleck Monday, June 16, 2014 9:59 PM General .Net question, not MDM.
    Monday, June 16, 2014 6:43 AM

Answers

  • Hi Umesh,

    I build a project to test. Add blank records to DataSet, but I can see them in XML. I use the following code.

     

    DataTable dt = new DataTable();
    
                DataColumn dc1 = new DataColumn("ID");
    
                DataColumn dc2 = new DataColumn("Title");
    
                dt.Columns.Add(dc1);
    
                dt.Columns.Add(dc2);
    
                for (int i = 0; i < 50; i++)
    
                {
    
                    DataRow newrow = dt.NewRow();
    
                    newrow["ID"] = "";
    
                    newrow["Title"] = "";
    
                    dt.Rows.Add(newrow);
    
                }
    
                DataSet ds = new DataSet();
    
                ds.Tables.Add(dt);
    
                var txt = ds.GetXml();
    

    Please post more information about this problem to help me reproduce this problem.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 17, 2014 5:31 AM
    Moderator
  • Seems that you have to deal with special file — XML Schema — and read it (from file or memory) using ReadXmlSchema. Set the nillable attribute to true: http://social.msdn.microsoft.com/Forums/en-US/e35f15f6-640f-4939-affd-dc25ff7ff8d9.

    Tuesday, June 17, 2014 7:49 AM

All replies

  • Hi Umesh,

    I build a project to test. Add blank records to DataSet, but I can see them in XML. I use the following code.

     

    DataTable dt = new DataTable();
    
                DataColumn dc1 = new DataColumn("ID");
    
                DataColumn dc2 = new DataColumn("Title");
    
                dt.Columns.Add(dc1);
    
                dt.Columns.Add(dc2);
    
                for (int i = 0; i < 50; i++)
    
                {
    
                    DataRow newrow = dt.NewRow();
    
                    newrow["ID"] = "";
    
                    newrow["Title"] = "";
    
                    dt.Rows.Add(newrow);
    
                }
    
                DataSet ds = new DataSet();
    
                ds.Tables.Add(dt);
    
                var txt = ds.GetXml();
    

    Please post more information about this problem to help me reproduce this problem.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 17, 2014 5:31 AM
    Moderator
  • Seems that you have to deal with special file — XML Schema — and read it (from file or memory) using ReadXmlSchema. Set the nillable attribute to true: http://social.msdn.microsoft.com/Forums/en-US/e35f15f6-640f-4939-affd-dc25ff7ff8d9.

    Tuesday, June 17, 2014 7:49 AM