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

(Beginner) Retrieve XML data into a Dataset

Hi, I searched through this newsgroup looking for an answer for this, but
didn't find any (it probably is here. Just didn't find it).

I am trying to retrieve information from two related tables, using For XML
Auto, and then use that in my C# app. I am only receiving the
first row (and its child rows). This is what I do:

Stored Procedure:
Create Procedure dbo.uspTest04
As
Select
Top 5
Oe.OrderID,
CustomerID,
EmployeeID,
ProductID ,
UnitPrice ,
Quantity ,
Discount
From dbo.Orders As Oe( NoLock )
Inner Join dbo.[Order Details] As Od( NoLock )
On Oe.OrderID = Od.OrderID
For XML Auto
Return

C# code:
SqlCommand cmmExecuteProcedure;
SqlConnection cnnTheConnection ;
DataSet dtsTablas ;

cnnTheConnection = new SqlConnection( strConnectionString );

cmmExecuteProcedure = new SqlCommand( "dbo.uspTest04", cnnTheConnection );
cmmExecuteProcedure.CommandType = CommandType.StoredProcedure;

cnnTheConnection.Open();

dtsTablas = new DataSet();
dtsTablas.ReadXml( cmmExecuteProcedure.ExecuteXmlReader() );

cnnTheConnection.Close();

dtgResultados.DataSource = dtsTablas;

If I use For XML Auto, XMLData in the stored procedure and specify the read
mode for the DataSet as 'fragment', it works. But SQL Server help suggests
not to use "XMLData":

Procedure:
Create Procedure dbo.uspTest05
As
Select
Top 5
Oe.OrderID,
CustomerID,
EmployeeID,
ProductID ,
UnitPrice ,
Quantity ,
Discount
From dbo.Orders As Oe( NoLock )
Inner Join dbo.[Order Details] As Od( NoLock )
On Oe.OrderID = Od.OrderID
For XML Auto, XMLData
Return

C# code:
SqlCommand cmmExecuteProcedure;
SqlConnection cnnTheConnection ;
DataSet dtsTablas ;

cnnTheConnection = new SqlConnection( strConnectionString );

cmmExecuteProcedure = new SqlCommand( "dbo.uspTest05", cnnTheConnection );
cmmExecuteProcedure.CommandType = CommandType.StoredProcedure;

cnnTheConnection.Open();

dtsTablas = new DataSet();
dtsTablas.ReadXml( cmmExecuteProcedure.ExecuteXmlReader(),
XmlReadMode.Fragment );

cnnTheConnection.Close();

dtgResultados.DataSource = dtsTablas;
What do I need to do, to receive all the information in the DataSet, without
using "For XML Auto, XMLData"? Also, I see that the XML result comes without
a

root. How do I make it come with a root, so that I can use, for example:

ThisXMLDocument.Load( cmmExecuteProcedure.ExecuteXmlReader() )

?

Thank you very much for the help. Have a great day,

Frank.
Nov 12 '05 #1
3 7300
I changed the client code to fill the Dataset, like this:

dtsResults = new DataSet();
while ( !xrdResults.EOF )
{
dtsResults.ReadXml( xrdResults );
}

And now, it looks like it works ok. I'm able to see all rows (and their
child rows). The stored procedure is using "For XML Auto" and not "For XML
Auto, XMLData". Is all this the correct way to do it, or should I use
xrdResults.MoveToContent() to avoid any possible error?

Thanks in advance,

Frank
"John Francisco Williams" <Cu******@e-ciety.com> wrote in message
news:eC**************@TK2MSFTNGP12.phx.gbl...
Hi, I searched through this newsgroup looking for an answer for this, but
didn't find any (it probably is here. Just didn't find it).

I am trying to retrieve information from two related tables, using For XML
Auto, and then use that in my C# app. I am only receiving the
first row (and its child rows). This is what I do:

Stored Procedure:
Create Procedure dbo.uspTest04
As
Select
Top 5
Oe.OrderID,
CustomerID,
EmployeeID,
ProductID ,
UnitPrice ,
Quantity ,
Discount
From dbo.Orders As Oe( NoLock )
Inner Join dbo.[Order Details] As Od( NoLock )
On Oe.OrderID = Od.OrderID
For XML Auto
Return

C# code:
SqlCommand cmmExecuteProcedure;
SqlConnection cnnTheConnection ;
DataSet dtsTablas ;

cnnTheConnection = new SqlConnection( strConnectionString );

cmmExecuteProcedure = new SqlCommand( "dbo.uspTest04", cnnTheConnection );
cmmExecuteProcedure.CommandType = CommandType.StoredProcedure;

cnnTheConnection.Open();

dtsTablas = new DataSet();
dtsTablas.ReadXml( cmmExecuteProcedure.ExecuteXmlReader() );

cnnTheConnection.Close();

dtgResultados.DataSource = dtsTablas;

If I use For XML Auto, XMLData in the stored procedure and specify the read mode for the DataSet as 'fragment', it works. But SQL Server help suggests
not to use "XMLData":

Procedure:
Create Procedure dbo.uspTest05
As
Select
Top 5
Oe.OrderID,
CustomerID,
EmployeeID,
ProductID ,
UnitPrice ,
Quantity ,
Discount
From dbo.Orders As Oe( NoLock )
Inner Join dbo.[Order Details] As Od( NoLock )
On Oe.OrderID = Od.OrderID
For XML Auto, XMLData
Return

C# code:
SqlCommand cmmExecuteProcedure;
SqlConnection cnnTheConnection ;
DataSet dtsTablas ;

cnnTheConnection = new SqlConnection( strConnectionString );

cmmExecuteProcedure = new SqlCommand( "dbo.uspTest05", cnnTheConnection );
cmmExecuteProcedure.CommandType = CommandType.StoredProcedure;

cnnTheConnection.Open();

dtsTablas = new DataSet();
dtsTablas.ReadXml( cmmExecuteProcedure.ExecuteXmlReader(),
XmlReadMode.Fragment );

cnnTheConnection.Close();

dtgResultados.DataSource = dtsTablas;
What do I need to do, to receive all the information in the DataSet, without using "For XML Auto, XMLData"? Also, I see that the XML result comes without a

root. How do I make it come with a root, so that I can use, for example:

ThisXMLDocument.Load( cmmExecuteProcedure.ExecuteXmlReader() )

?

Thank you very much for the help. Have a great day,

Frank.

Nov 12 '05 #2
"John Francisco Williams" <Cu******@e-ciety.com> wrote in message
news:eC**************@TK2MSFTNGP12.phx.gbl...
[snip]
I am trying to retrieve information from two related tables, using For XML
Auto, and then use that in my C# app. I am only receiving the
first row (and its child rows). This is what I do:


Take a look at the SQLXML Managed Classes:
http://msdn.microsoft.com/library/en...otnet_775e.asp

--
Bryant
Nov 12 '05 #3
Excelent :-) Thank you very much

Frank

"Bryant Likes" <br****@suespammers.org> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"John Francisco Williams" <Cu******@e-ciety.com> wrote in message
news:eC**************@TK2MSFTNGP12.phx.gbl...
[snip]
I am trying to retrieve information from two related tables, using For XML Auto, and then use that in my C# app. I am only receiving the
first row (and its child rows). This is what I do:


Take a look at the SQLXML Managed Classes:
http://msdn.microsoft.com/library/en...otnet_775e.asp

--
Bryant

Nov 12 '05 #4

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

Similar topics

1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
7
by: Shaine Fisher | last post by:
I have had a look around but I'm either not finding or not seeing the answer to this, what i want to do is reurn the results as an array, or some other worldly useful format that flash mx2004 can...
4
by: Claudia Fong | last post by:
Hi, I have a form where I need to display the data of a department that stores in a access db. When I first load the form it will call a function name loaddata which will get the first...
4
by: jay | last post by:
I am using the dataset object to add a row to a sql server database in vb.net code, as follows: dim drow as DataRow dim cmdBld as new SqlCommandBuilder(mySqlDataAdapter) ds.tables(0).NewRow()...
5
by: mark | last post by:
I've been looking at working with Excel data. I understand the process of getting the data into a dataset and modifying it. It's one of simple beauty that is well documented. Now, I want to send...
0
by: r1 | last post by:
I am relatively inexperienced in using delegates and asynchronous methods. I read several articles, and then I developed my own code with a mission to improve the performance. Wow! I cannot...
1
by: j.t.w | last post by:
Hi. I'm new to ASP.Net and I'm running into a simple problem (I think). I'm trying to get 2 values from 2 separate queries into 2 different variables. I would then like to take the difference...
1
by: whidbey | last post by:
Hello friends, I am whidbey, new to thescripts and dot net as well.I am working over Online Shopping Cart,web application.I design a page (webform5.aspx) where user search books then select the books...
0
by: whidbey | last post by:
Hello friends, I am whidbey, new to thescripts and dot net as well.I am working over Online Shopping Cart,web application.I design a page (webform5.aspx) where user search books then select the books...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.