473,320 Members | 2,073 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,320 software developers and data experts.

SqlCommand.ExecuteXmlReader

Hi,

When executing following statement "select distinct Name from
CustomerParameters for xml auto"

- XmlReader reads "<customerparameters name="Www.Mail.Generel" />"
- but SQL Query Manager returns "<CustomerParameters
Name="Www.Mail.Generel"/><CustomerParameters Name="Www.Mail.Updates"/>"

I'm using following to read the result returned from the SqlConnection

string result = "";

SqlCommand comm = conn.CreateCommand();
comm.CommandType = CommandType.Text;
comm.CommandText = sql;

XmlReader reader = comm.ExecuteXmlReader();
reader.MoveToContent();
result = reader.ReadOuterXml();
reader.Close();

comm.Dispose();

Why the difference ??

Thanks in advance

Soren
Nov 16 '05 #1
1 3936
Hello Soren,

You have forgotten a loop.

Normally, XML Reader expects to read a single XML document. A single XML
document will have a parent node and one or more child nodes:
<parent>
<child/>
<child/>
</parent>

However, SQL Server doesn't return an XML document. It just returns the
child nodes:
<child/>
<child/>

As such, the XML Reader finds the first node, assumes that it is the entire
document, and returns it.

You need to put XML Reader in a loop to get all the records.

See an example at:
http://support.microsoft.com/default...316016&SD=MSDN

Hope this helps,
--- Nick

"Soren Jorgensen" <no@spam.com> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
Hi,

When executing following statement "select distinct Name from
CustomerParameters for xml auto"

- XmlReader reads "<customerparameters name="Www.Mail.Generel" />"
- but SQL Query Manager returns "<CustomerParameters
Name="Www.Mail.Generel"/><CustomerParameters Name="Www.Mail.Updates"/>"

I'm using following to read the result returned from the SqlConnection

string result = "";

SqlCommand comm = conn.CreateCommand();
comm.CommandType = CommandType.Text;
comm.CommandText = sql;

XmlReader reader = comm.ExecuteXmlReader();
reader.MoveToContent();
result = reader.ReadOuterXml();
reader.Close();

comm.Dispose();

Why the difference ??

Thanks in advance

Soren

Nov 16 '05 #2

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: 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...
10
by: Henrik Dahl | last post by:
Hello! After I've finished using an instance of the SqlCommand class, should I then invoke Dispose() on the instance. I suppose so, as there is a Dispose method, but what does it actually...
8
by: terrorix | last post by:
I also posted this article at: microsoft.public.dotnet.framework.aspnet -------- Hi, I Have this sql select(MS SQL): select a.ID, b.ID from Table as a
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: Tom | last post by:
Hello guys Please have a look on following paragraph from ".NET Data Access Architecture Guide". ''''''''''' Although you can repeatedly use the same SqlCommand object to execute the same...
1
by: job | last post by:
how is it possible to serialize/de-serialize a SqlCommand?
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.