Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8036177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:31:53+00:00 2026-06-05T02:31:53+00:00

I need to export a DataSet to XML but all cells with the DBNull

  • 0

I need to export a DataSet to XML but all cells with the DBNull value disappear from the final XML file. DBNull values are in the middle of the table, so columns(in rows with dbnull) shift and deface the entire table.

public static string GetXmlFromDataSet(DataSet ds)
            {
                try
                {
                    StringWriter sw = new StringWriter();
                    ds.WriteXml(sw);
                    string outputXml = sw.ToString();

                    return outputXml;
                }
                catch (Exception ex)
                {
                    return ex.ToString();
                }
            }

Then XslCompiledTransform makes the file readable for MS Excel. But without some of the cells it is unusable. I need help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:31:55+00:00Added an answer on June 5, 2026 at 2:31 am

    I wrote XML parser and it solves this problem. When DataSet.WriteXML saw DBNULL value in the Dataset, it will not record to the XML file.

    Standart method DataSet.WriteXML have an property XmlWriteMode. If you use XmlWriteMode.WriteSchema WriteXML method record schema at the top of XML file. But it works if you will convert it XML to DataSet. In my case XML file transforms to Excel by using XslCompiledTransform, so schema can’t help me.

    This is code of my solution:

    try
    {
       StringWriter sw = new StringWriter();
    
       //ds.WriteXml(sw, XmlWriteMode.IgnoreSchema);
       DataTable dt = ds.Tables[0];
       sw.Write(@"<NewDataSet>");
       foreach (DataRow row in dt.Rows)
       {
          sw.Write(@"<Table>");
          foreach (DataColumn col in dt.Columns)
          {
             sw.Write(@"<" + XmlConvert.EncodeName(col.ColumnName) + @">");
             sw.Write(row[col]);
             sw.Write(@"</" + XmlConvert.EncodeName(col.ColumnName) + @">");
          }
          sw.Write(@"</Table>");
       }
       sw.Write(@"</NewDataSet>");
       return sw.ToString();
    }
    catch (Exception ex)
    {
       return ex.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to export some numeric values from a given ASCII text file and
I need a solution to export a dataset to an excel file without any
I need to export csv file in php using mysql query .But when i
I need to export an SQLite database from an Android phone to a computer.
I need to export my gridview data to excel. No problems for this. All
I need to export a matrix of regression results from Stata to MATLAB. I
being in need to export a DOC file to TXT and then reimport it
I am completely new to VBA and need to export multiple graphs from an
I need to be able to export the domain's XML configs to XEN config
I need to export about 300,000 rows from a table on MS SQL server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.