Re: Retrieve XML Data

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: cyphos (mweichert_at_wightman-dot-ca.no-spam.invalid)
Date: 12/07/04


Date: 7 Dec 2004 14:00:06 -0600

Hi,

Create a SqlCommand object with your select command.

so...

// Create query
string query = "SELECT website.websiteID, website.description,
website.URL, website.DepartmentID FROM website WHERE
website.canDisplay = 1 FOR XML AUTO, ELEMENTS";

// Create command
SqlCommand cmd = new SqlCommand(query, myConnectionObject);

// Create data adapter
SqlDataAdapter da = new SqlDataAdapter(cmd);

// Create dataset
DataSet ds = new DataSet();

// Fill the dataset
da.Fill(ds, "Website");

// Write the xml
ds.WriteXml("C:\test.xml");

Hope that helps. :)
> nyousfiwrote:
Hi everyone,
>
> I hope you can help!
>
> I have the following query accesing an SQL Server 2000 Box
>
> SELECT website.websiteID,
> website.description,
> website.URL,
> website.DepartmentID
> FROM website
> WHERE website.canDisplay = 1
>
> FOR XML AUTO, ELEMENTS
>
> This comes back with
>
> <website>
> <websiteID>1</websiteID>
> <description>yahoo</description>
> <URL>http://www.yahoo.com>
> <DepartmentID>Department1</DepartmentID>
> </website>
>
> Now, thats the easy bit, any idea how I can save the Data coming
back into an XML file?
>
> i.e. I want to save the data to c:\test.xml
>
> Not sure what to use.
>
> Thanks for the help![/code]

*-----------------------*
        Posted at:
  www.GroupSrv.com
*-----------------------*



Relevant Pages

  • Re: Getting results of a FOR Command
    ... I can issue the following command in SQL ... From Customer FOR XML AUTO ...
    (borland.public.delphi.database.ado)
  • Re: Getting results of a FOR Command
    ... "FOR XML AUTO" is a Microsoft Command to format the results of ... After I execute the full select statement I want to be able to ... I can issue the following command in SQL ... From Customer FOR XML AUTO ...
    (borland.public.delphi.database.ado)
  • XML
    ... Have a look at the 'FOR XML' command on BOL for select ... select * from myTable for XML auto ... Peter ...
    (microsoft.public.sqlserver.server)
  • RE: XML From Store procedure HELP
    ... SqlCommand Object has a method named "ExecuteXmlReader" which ... can return XML from a query like "select * from XXX FOR XML AUTO". ... Use the ExecuteXmlReader Method of the SqlCommand Class in Visual ...
    (microsoft.public.dotnet.framework.adonet)