473,378 Members | 1,658 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,378 software developers and data experts.

ExecuteXmlReader w/ Multiple result sets from SP

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 @Type='Rushing'>
<LEADER @Carries=''/>
</LEADERBOARD>
<LEADERBOARD @Type='QBRating'>
<LEADER @Rating='' @CompletionPct=''/>
</LEADERBOARD>
<LEADERBOARD @Type='Tackles'>
<LEADER @Assisted='' @Tackles='' @Total=''/>
</LEADERBOARD>

I need to take the output and use XSLT to translate it to custom output. But
no matter what I try I hit a dead end. Following is what I have tried.
1)
CREATE PROCEDURE GetAllLeaders_XML
@Param1, @Param2, @Param3
AS

SET NOCOUNT ON

SELECT '<LEADERBOARDS>'
EXEC Leaderboard_XML @LeaderType1, @param1, @param2, @param3
EXEC Leaderboard_XML @LeaderType2, @param1, @param2, @param3
EXEC Leaderboard_XML @LeaderType3, @param1, @param2, @param3
SELECT '</LEADERBOARDS>'

GO

with the following code (C#):
XmlReader rdrXml = cmdXML.ExecuteXmlReader();

or this:

DataSet dsXML = new DataSet();

dsXML.ReadXml(cmdXML.ExecuteXmlReader(), XmlReadMode.Fragment);

result: "Invalid command sent to ExecuteXmlReader(). The command must return
an XML result.
2) If I remove the "root" LEADERBOARDS from before and after the sp's:

with the same code (C#)
(see #1 above)

result: "Object reference not set to an instance of an object. "

(btw. It doesn't matter if I use "ROOT" or "LEADERBOARDS" as the root
element).

I have looked at SqlXmlCommand but I don't see how I can add multiple
parameters to pass to the sp. So if anyone can point me in the right
direction or provide me with some sample code to that effect I'd appreciate
any help. Even if only to let me know if I could get a better answer from
another ng. Everything I have tried works fine w/ other sp's that return a
single, well-formed frament w/ a root element. I need help ASAP,
PLEEEEAASSSEEEEEE!
Nov 11 '05 #1
3 7700
Inside those stored procedures - you are doing "for xml" on the select
statements??
"Mark Miller" <no**********@waveshift.com> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
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 @Type='Rushing'>
<LEADER @Carries=''/>
</LEADERBOARD>
<LEADERBOARD @Type='QBRating'>
<LEADER @Rating='' @CompletionPct=''/>
</LEADERBOARD>
<LEADERBOARD @Type='Tackles'>
<LEADER @Assisted='' @Tackles='' @Total=''/>
</LEADERBOARD>

I need to take the output and use XSLT to translate it to custom output. But no matter what I try I hit a dead end. Following is what I have tried.
1)
CREATE PROCEDURE GetAllLeaders_XML
@Param1, @Param2, @Param3
AS

SET NOCOUNT ON

SELECT '<LEADERBOARDS>'
EXEC Leaderboard_XML @LeaderType1, @param1, @param2, @param3
EXEC Leaderboard_XML @LeaderType2, @param1, @param2, @param3
EXEC Leaderboard_XML @LeaderType3, @param1, @param2, @param3
SELECT '</LEADERBOARDS>'

GO

with the following code (C#):
XmlReader rdrXml = cmdXML.ExecuteXmlReader();

or this:

DataSet dsXML = new DataSet();

dsXML.ReadXml(cmdXML.ExecuteXmlReader(), XmlReadMode.Fragment);

result: "Invalid command sent to ExecuteXmlReader(). The command must return an XML result.
2) If I remove the "root" LEADERBOARDS from before and after the sp's:

with the same code (C#)
(see #1 above)

result: "Object reference not set to an instance of an object. "

(btw. It doesn't matter if I use "ROOT" or "LEADERBOARDS" as the root
element).

I have looked at SqlXmlCommand but I don't see how I can add multiple
parameters to pass to the sp. So if anyone can point me in the right
direction or provide me with some sample code to that effect I'd appreciate any help. Even if only to let me know if I could get a better answer from
another ng. Everything I have tried works fine w/ other sp's that return a
single, well-formed frament w/ a root element. I need help ASAP,
PLEEEEAASSSEEEEEE!

Nov 11 '05 #2
If you are referring to the statments:
SELECT '<LEADERBOARDS>'
and
SELECT '</LEADERBOARDS>'

no, I am not. I was not aware that was possible. Won't that wrap the text
"<LEADERBOARDS>" in another XML tag? If this is what you are referring to
could you please provide a sample of how I would do that?

But if you are referring to the statements
EXEC Leaderboard_XML @LeaderType1, @param1, @param2, @param3
EXEC Leaderboard_XML @LeaderType2, @param1, @param2, @param3
EXEC Leaderboard_XML @LeaderType3, @param1, @param2, @param3

Yes, I am. I am using FOR XML EXPLICIT

"Drebin" <tR*************@hotmail.com> wrote in message
news:ur*****************@newssvr33.news.prodigy.co m...
Inside those stored procedures - you are doing "for xml" on the select
statements??
"Mark Miller" <no**********@waveshift.com> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
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 @Type='Rushing'>
<LEADER @Carries=''/>
</LEADERBOARD>
<LEADERBOARD @Type='QBRating'>
<LEADER @Rating='' @CompletionPct=''/>
</LEADERBOARD>
<LEADERBOARD @Type='Tackles'>
<LEADER @Assisted='' @Tackles='' @Total=''/>
</LEADERBOARD>

I need to take the output and use XSLT to translate it to custom output.

But
no matter what I try I hit a dead end. Following is what I have tried.
1)
CREATE PROCEDURE GetAllLeaders_XML
@Param1, @Param2, @Param3
AS

SET NOCOUNT ON

SELECT '<LEADERBOARDS>'
EXEC Leaderboard_XML @LeaderType1, @param1, @param2, @param3
EXEC Leaderboard_XML @LeaderType2, @param1, @param2, @param3
EXEC Leaderboard_XML @LeaderType3, @param1, @param2, @param3
SELECT '</LEADERBOARDS>'

GO

with the following code (C#):
XmlReader rdrXml = cmdXML.ExecuteXmlReader();

or this:

DataSet dsXML = new DataSet();

dsXML.ReadXml(cmdXML.ExecuteXmlReader(), XmlReadMode.Fragment);

result: "Invalid command sent to ExecuteXmlReader(). The command must

return
an XML result.
2) If I remove the "root" LEADERBOARDS from before and after the sp's:

with the same code (C#)
(see #1 above)

result: "Object reference not set to an instance of an object. "

(btw. It doesn't matter if I use "ROOT" or "LEADERBOARDS" as the root
element).

I have looked at SqlXmlCommand but I don't see how I can add multiple
parameters to pass to the sp. So if anyone can point me in the right
direction or provide me with some sample code to that effect I'd

appreciate
any help. Even if only to let me know if I could get a better answer from another ng. Everything I have tried works fine w/ other sp's that return a single, well-formed frament w/ a root element. I need help ASAP,
PLEEEEAASSSEEEEEE!


Nov 11 '05 #3
I appreciate your help. However, my problem actually lies with getting the
result set to the client. The root node is the least of my worries. I only
added it hoping the ExecuteXmlReader method would then interpret the
resulting stream as a well formed XML document as opposed to a bunch of
fragments which is what I think it is doing.

I'm going to look into using a standard SqlDataReader or DataSet object to
get the data and then glue it all together before trying to pass it off as
all one XML docuement. But please if anyone has a better solution or can
point me in the right direction to using the SqlXmlCommand object I would
appreciate it.

Thanks,
mark
"Drebin" <tR*************@hotmail.com> wrote in message
news:N2*****************@newssvr32.news.prodigy.co m...
Yeah, you are right, you can only do individual tags, like this:

SELECT TOP 1
1 as Tag,
NULL as Parent,
GetDate() as [Leaderboard!1!]
FOR XML EXPLICIT

But not put the entire bit within that container - which is what I was
thinking.. My bad.

On another note, when I've done this in ASP, I always put the outside
container (like Leaderboard) on the client-side, then inserted the rest of
the XML inside that node.. but I should note, I have yet to get a .NET
version of this concept working, so I'm not much of an expert... :o)
"Mark Miller" <no**********@waveshift.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
If you are referring to the statments:
SELECT '<LEADERBOARDS>'
and
SELECT '</LEADERBOARDS>'

no, I am not. I was not aware that was possible. Won't that wrap the text
"<LEADERBOARDS>" in another XML tag? If this is what you are referring to could you please provide a sample of how I would do that?

But if you are referring to the statements
EXEC Leaderboard_XML @LeaderType1, @param1, @param2, @param3
EXEC Leaderboard_XML @LeaderType2, @param1, @param2, @param3
EXEC Leaderboard_XML @LeaderType3, @param1, @param2, @param3

Yes, I am. I am using FOR XML EXPLICIT

"Drebin" <tR*************@hotmail.com> wrote in message
news:ur*****************@newssvr33.news.prodigy.co m...
Inside those stored procedures - you are doing "for xml" on the select
statements??
"Mark Miller" <no**********@waveshift.com> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
> 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 @Type='Rushing'>
> <LEADER @Carries=''/>
> </LEADERBOARD>
> <LEADERBOARD @Type='QBRating'>
> <LEADER @Rating='' @CompletionPct=''/>
> </LEADERBOARD>
> <LEADERBOARD @Type='Tackles'>
> <LEADER @Assisted='' @Tackles='' @Total=''/>
> </LEADERBOARD>
>
> I need to take the output and use XSLT to translate it to custom

output. But
> no matter what I try I hit a dead end. Following is what I have tried. > 1)
> CREATE PROCEDURE GetAllLeaders_XML
> @Param1, @Param2, @Param3
> AS
>
> SET NOCOUNT ON
>
> SELECT '<LEADERBOARDS>'
> EXEC Leaderboard_XML @LeaderType1, @param1, @param2, @param3
> EXEC Leaderboard_XML @LeaderType2, @param1, @param2, @param3
> EXEC Leaderboard_XML @LeaderType3, @param1, @param2, @param3
> SELECT '</LEADERBOARDS>'
>
> GO
>
> with the following code (C#):
> XmlReader rdrXml = cmdXML.ExecuteXmlReader();
>
> or this:
>
> DataSet dsXML = new DataSet();
>
> dsXML.ReadXml(cmdXML.ExecuteXmlReader(), XmlReadMode.Fragment);
>
>
>
> result: "Invalid command sent to ExecuteXmlReader(). The command must return
> an XML result.
>
>
> 2) If I remove the "root" LEADERBOARDS from before and after the sp's: >
> with the same code (C#)
> (see #1 above)
>
> result: "Object reference not set to an instance of an object. "
>
> (btw. It doesn't matter if I use "ROOT" or "LEADERBOARDS" as the root > element).
>
> I have looked at SqlXmlCommand but I don't see how I can add multiple > parameters to pass to the sp. So if anyone can point me in the right
> direction or provide me with some sample code to that effect I'd
appreciate
> any help. Even if only to let me know if I could get a better answer

from
> another ng. Everything I have tried works fine w/ other sp's that

return
a
> single, well-formed frament w/ a root element. I need help ASAP,
> PLEEEEAASSSEEEEEE!
>
>



Nov 11 '05 #4

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

Similar topics

2
by: Darko Jovisic | last post by:
Hi! Another silly question: If a stored procedure returns multiple result sets, how do I choose the one I want to insert into a table? For example sp_spaceused returns two result sets if...
4
by: randy.p.ho | last post by:
Using JDBC, is there a way to call a stored procedure with multiple return values? Thanks.
3
by: wxbuff | last post by:
I have a report based on our product names that consists of two parts. Both insert data into a temporary table. 1. A single grouped set of results based on all products 2. Multiple tables based...
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...
0
by: Steve Harclerode | last post by:
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...
5
by: Stanley Sinclair | last post by:
I have a need to return multiple result sets from a stored procedure. Want that SP to call others to get the data. Win2003, db2 8.1.5. Can't figure out how to handle open cursors, and return...
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....
15
by: AussieRules | last post by:
Hi, I have a need to do two selects against to stored proc's in my SQL db. At the moment, each SP is called and two different dataset are populate. Thats two round trips to the SQL server. ...
1
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: 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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.