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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:38:19+00:00 2026-06-14T11:38:19+00:00

My primary coding ideal is on .net applications.. So I have limited skill with

  • 0

My primary coding ideal is on .net applications.. So I have limited skill with application design.

I am trying to export an entire table from a database (Using a view) to an XML file (To then hopefully export that to a spreadsheet – I’ve looked and fail to find a direct way).

I have successfully exported only 1 column to the xml file, using this code:

DataConn.UserName = "***";
DataConn.Password = "***";
DataConn.SqlServer = "***";
DataConn.Database = "***";

const string strSql = "SELECT TOP 1 * FROM vwGetStaffDetails FOR XML AUTO";

using (SqlCommand sqlComm = new SqlCommand(strSql, DataConn.Connect()) { CommandType = CommandType.Text })
{
     string result = sqlComm.ExecuteScalar().ToString();

     File.WriteAllText(@"C:\Temp\text.xml", result);
 }

Whenever I use ExecuteReader or ExecuteXmlReader, I don’t get any actual results.

How would I get all the fields?

Edit: I had to use Top 1 to get the Execute Scalar working well.

Using the below solution, my file shows:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Table>
    <XML_F52E2B61-18A1-11d1-B105-00805F49916B>&lt;vwGetStaffDetails ImageLoc="****.jpg" LName="GAINES" FName="****" StaffTitle="****" JobPosition="****" Email="***@***.com" Code="***" Number="******" PhoneTypeID="1"/&gt;</XML_F52E2B61-18A1-11d1-B105-00805F49916B>
  </Table>
</NewDataSet>

It’s writing &lt; etc instead of proper XML. Is the any way to fix it?

  • 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-14T11:38:21+00:00Added an answer on June 14, 2026 at 11:38 am

    You can use a SqlDataAdapter and System.Data.DataSet to load a DataTable, which will write to XML.

    const string strSql = "SELECT * FROM vwGetStaffDetails";
    
    using (SqlCommand sqlComm = new SqlCommand(strSql, DataConn.Connect()) { CommandType = CommandType.Text })
    {
        SqlDataAdapter da = new SqlDataAdapter(sqlComm);
        DataSet ds = new DataSet();
        da.Fill(ds);
        ds.Tables[0].WriteXml(@"C:\Temp\text.xml");
    }
    

    Edit Using this method you’ll remove the XML code from SQL and let .NET convert everything. I’ve changed your SQL command to reflect this.

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

Sidebar

Related Questions

We have a composite primary key for the site table defined below. Functionally, this
Strange situation: I am trying to remove some hard coding from my code. There
I have a couple of tables in a web application I'm coding in PHP,
I'm working with an MSSQL table that does not have a primary or unique
So I started my coding wit MYSQL and I have a table like following
table : id (integer primary key) data (blob) I use mysql and sqlalchemy. To
What should the Primary key be in the Employee Table? Table Stores (PK) StoreID
I am the primary developer on a Rails application that allows customers to manage
I have a primary key set up to auto increment. I am doing multiple
I'm currently coding a product which will have only one database but will host

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.