Re: Retrieve XML Data
From: cyphos (mweichert_at_wightman-dot-ca.no-spam.invalid)
Date: 12/07/04
- Next message: djc: "problem declaring SqlParameter of type Decimal"
- Previous message: cyphos: "XPath problems..."
- In reply to: nyousfi: "Retrieve XML Data"
- Next in thread: Sahil Malik: "Re: Retrieve XML Data"
- Messages sorted by: [ date ] [ thread ]
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
*-----------------------*
- Next message: djc: "problem declaring SqlParameter of type Decimal"
- Previous message: cyphos: "XPath problems..."
- In reply to: nyousfi: "Retrieve XML Data"
- Next in thread: Sahil Malik: "Re: Retrieve XML Data"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|