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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:28:24+00:00 2026-06-03T05:28:24+00:00

Hello all and thanks for the help, I need to write every row from

  • 0

Hello all and thanks for the help,
I need to write every row from one of my t-sql table columns into an xml file as a child. my current code OVER writes the last entry as it loops. The result should look like

(desired result)
<array> 
<element>data1</element>
<element>data2</element>
<element>data3</element>
<element>data4</element>
<element>data5</element>
</array>

Not (currently)

<array>
<element>data5</element> (the last entry in table column)
</array>

What am I missing ?
Thanks Again your time is much appreciated.

public void Download_Click(object sender, EventArgs e)
{

       string AddressVal;
       string invoiceVal;

       SqlConnection conn = null;
       SqlConnection connTwo = null;
       try
       {



           //**************************************
           string connStr2 = ConfigurationManager.ConnectionStrings["MYConString"].ConnectionString;
           string cmdStr2 = "select * from t_BannerUser";

           connTwo = new SqlConnection(connStr2);
           SqlCommand oleComm2 = new SqlCommand(cmdStr2, connTwo);
           connTwo.Open();
           SqlDataReader oleReader2 = oleComm2.ExecuteReader();
           //************************************** DATATABLE TEST *************
           //SqlDataAdapter da = new SqlDataAdapter(cmdStr2, connStr2);
           //DataTable dt = new DataTable();
           //da.Fill(dt);

           //for (int i = 0; i < dt.Rows.Count; i++)
           //{
           //****************************
           while (oleReader2.Read())
           {

             //  AddressVal = oleReader["c_user"].ToString();
               invoiceVal = oleReader2["c_user_id"].ToString();

        //create XMLTextWriter object and set its save location
        //…the second value is for an Encoding declaration I found to be unnecessary, hence, null
        XmlTextWriter plist = new XmlTextWriter("C:/Temp/plistName.plist", null);
        //assign basic formatting to the XMLTextWriter so that the XML is easily legible
        plist.Formatting = Formatting.Indented;
        //default indentation is 2 spaces; 4 spaces is essentially one “tab”
        plist.Indentation = 4;



        //create the initial xml element to start the document
        plist.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
//create a custom DTD
plist.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);

        //create root element
plist.WriteStartElement("plist");
//assign version attribute
plist.WriteAttributeString("version", "1.0");
//creating a dict element before anything else is required
plist.WriteStartElement("dict");
//create the array key (shows up as the array name when viewing the .plist)
plist.WriteElementString("key", "ArrayName");
//you have to then create the array!
plist.WriteStartElement("array");



//create a dict element to arrange succeeding object attributes
plist.WriteStartElement("dict");
//create key element (shows as item name when viewing the plist)
plist.WriteElementString("key", "KeyName");
//create string element (shows as item value when viewing the plist)
//plist.WriteElementString("string", dt.Rows[i]["c_user_id"].ToString());
plist.WriteElementString("string", invoiceVal.ToString());
//create the array key (shows up as the array name when viewing the plist)
plist.WriteElementString("key", "ArrayName");
//you have to then create the array!
plist.WriteStartElement("array");



        //create a dict element to arrange succeeding object attributes
plist.WriteStartElement("dict");
//create key element (shows as item name when viewing the plist)
plist.WriteElementString("key", "KeyName");
//create string element (shows as item value when viewing the plist)
//plist.WriteElementString("string", DataTable.Rows[int]["ColumnName"].ToString());
plist.WriteElementString("string", invoiceVal.ToString());


plist.Flush();
plist.Close();

              // }
           }

       }

           catch (Exception ex)
       {
           Debug.WriteLine(ex.Message);
       }
    }
  • 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-03T05:28:25+00:00Added an answer on June 3, 2026 at 5:28 am

    You code is creating the file at the start of each iteration of the while loop (as well as closing an flushing it at the end of the while loop). Move that code outside the while loop and you’ll have better results.

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

Sidebar

Related Questions

Hello all and thanks for your time reading this. I need to verify certificates
Thanks for all the great answers, this helps a lot! Hello, I need some
hello all this seems to be my problem I have a table in mysql
var doc = w.document; doc.open('application/CSV','replace'); doc.charset = utf-8; doc.write(all,hello); doc.close(); if(doc.execCommand(SaveAs,null,file.csv)) { window.alert(saved );
hello guys I am trying to extract all the anchor links from aol but
Hello i have the this problem, i need your help to figure out what
Hello all I hope someone can help me I am working on a simple
Hello All I am using infragsitics tree view control.I have one stored procedure that
Hello all Thanks for your previous replies hey i am unable to install the
I need to remove all brackets and their contents from multiple records but I

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.