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 6386555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:02:27+00:00 2026-05-25T03:02:27+00:00

I am trying to output a XML file by fetching data from a dataset.

  • 0

I am trying to output a XML file by fetching data from a dataset. However, the xml file is always empty. Could you please help me to find the error in my code?

class Program
{
    static void Main(string[] args)
    {
        string umail = "";
        XDocument loaded = XDocument.Load(@"C:\1.xml");

        var q = from c in loaded.Descendants("AdminUserDB.dbo.U_User")
                select (string)c.Element("URI");

        foreach (string em in q)
            umail = em;

        SqlConnection cn = new SqlConnection("server=(local);database=AdminUserDB;Persist Security Info=True; uid=sa;pwd=P@swrd123");
        cn.Open();

        DataSet ds = new DataSet();

        SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM dbo.U_User WHERE URI=@umail", cn);

        da.SelectCommand.Parameters.AddWithValue("@umail", umail);

        da.Fill(ds);

        string filename = "output.xml";

        System.IO.FileStream myFileStream = new System.IO.FileStream(filename, System.IO.FileMode.Create);

        System.Xml.XmlTextWriter myXmlWriter = new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);

        ds.WriteXml(myXmlWriter);

        myXmlWriter.Close();

        cn.Close();

    }
}

}

I am also trying to use DataSet.WriteXml method directly, however, I could not find which namespace should be referenced. I searched for WriteXml on MSDN, but I could not find the System.Data.DataSet namespace, which is listed on the WriteXml method page.

Thanks

SuT

  • 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-05-25T03:02:28+00:00Added an answer on May 25, 2026 at 3:02 am

    Your code is leaking resources, always dispose disposable objects immediately. Otherwise you’ll be leaving files locked, and consume resources. Close doesn’t call Dispose.

    DataSet ds = new DataSet();
    
    using(SqlConnection cn = new SqlConnection("server=(local);database=AdminUserDB;Persist Security Info=True; uid=sa;pwd=P@swrd123"))
    {
        cn.Open();
    
        using(SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM dbo.U_User WHERE URI=@umail", cn))
        {
            da.SelectCommand.Parameters.AddWithValue("@umail", umail);
            da.Fill(ds);
        }
    }
    
    string filename = "output.xml";
    
    using(FileStream myFileStream = new FileStream(filename, FileMode.Create))
    {
        using(XmlTextWriter myXmlWriter = new XmlTextWriter(myFileStream, Encoding.Unicode))
        {
            ds.WriteXml(myXmlWriter);
        }
    }
    

    If after calling dispose on your streams you still don’t see anything there’s prob no data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to output a XML file using Python and lxml However, I
I am trying to generate an output XML file from a master xml file
I am trying to output the text from xml through an html file.Xml file
I'm trying to parse an xml file output from googletest to display the results
I have an XML input file and I'm trying to output the result of
I'm trying to disable log output from all external libraries in logback-test.xml. Somehow it
I'm trying to use XSL-stylesheets in order to transform some generated XML-data to HTML-output.
I am trying to output values of each rows from a DataSet : for
I'm trying to output an xml file blog.xml as yaml, for dropping into vision.app,
I'm parsing an XML file and trying to return the output to a div.

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.