473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

ExecuteXmlReader - How to Use?

I'm trying to use an SqlCommand.ExecuteXmlReader() to write data to an XML
file. Most of the code is below. The result I'm seeing is that the schema
file is written and looks good, but the XML file has no data other than an
empty <root> node. Is there something simple I'm missing? BTW, running the
same query in query analyzer returns 7 nodes.

Thanks --
Steve

--------------------

string cmdString = "SELECT * FROM TestTable order by column1 FOR XML
AUTO, XMLDATA";
DataSet ds = new DataSet();

using ( SqlConnection sc = new SqlConnection( connectionString ) )
{
sc.Open();
SqlCommand cmd = new SqlCommand( cmdString, sc );

XmlReader xr = cmd.ExecuteXmlReader();
ds.ReadXmlSchema( xr );
ds.ReadXml( xr, XmlReadMode.Fragment );
sc.Close();
}

ds.DataSetName = "root";
ds.WriteXml( @"C:\Test.xml" );
ds.WriteXmlSchema( @"C:\Test.xsd" );
Nov 12 '05 #1
0 1041

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark Miller | last post by:
I have an sp that outputs multiple xml fragments w/ no root. The sp calls individual sp's to output the correct set of data and each "type" has different fields. ex.: <LEADERBOARD...
2
by: Keith Chadwick | last post by:
I noticed an earlier post, Multiple External References in Transform - Background to the problem - Long Post, where the poster referenced an object entitled SqlXmlCommand. I am unable to find this...
2
by: Dylan Phillips | last post by:
A strang error is occurring when I run the following code: SqlConnection c = new SqlConnection(); c.ConnectionString = "Initial Catalog=Northwind;user id=sa;password=kat1ie;Data Source=server";...
5
by: adolf garlic | last post by:
Im trying to return xml from sql. The xml is made up of different fragments, some using FOR XML ... syntax. The result is a valid xml doc. There is a working stored proc that returns the xml In...
1
by: Adam Smith | last post by:
When executing ExecuteXmlReader() against a table where records are being inserted, I get: 9/5/2003 8:39:47 AM Transaction (Process ID 66) was deadlocked on lock resources with another process...
1
by: Soren Jorgensen | last post by:
Hi, When executing following statement "select distinct Name from CustomerParameters for xml auto" - XmlReader reads "<customerparameters name="Www.Mail.Generel" />" - but SQL Query Manager...
4
by: Steve Harclerode | last post by:
I tried this on another newsgroup but no nibbles -- I'm hoping someone might be able to help on this csharp group -- I'm trying to use SqlCommand.ExecuteXmlReader() to write data to an XML file....
1
by: Risen | last post by:
Hi, When I use sqlcommand.ExecuteXmlReader to receive Sql Server 2005's table data, it not work! my code is below: private static void CreateXMLReader(string queryString,string...
5
by: gurufordy | last post by:
Hello all. I have a stored procedure that take no parameters and just returns XML as below: CREATE PROCEDURE . AS SELECT vchrOne, vchrTwo, vchrThree
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.