473,609 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(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 cmmExecuteProce dure;
SqlConnection cnnTheConnectio n ;
DataSet dtsTablas ;

cnnTheConnectio n = new SqlConnection( strConnectionSt ring );

cmmExecuteProce dure = new SqlCommand( "dbo.uspTest04" , cnnTheConnectio n );
cmmExecuteProce dure.CommandTyp e = CommandType.Sto redProcedure;

cnnTheConnectio n.Open();

dtsTablas = new DataSet();
dtsTablas.ReadX ml( cmmExecuteProce dure.ExecuteXml Reader() );

cnnTheConnectio n.Close();

dtgResultados.D ataSource = 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 cmmExecuteProce dure;
SqlConnection cnnTheConnectio n ;
DataSet dtsTablas ;

cnnTheConnectio n = new SqlConnection( strConnectionSt ring );

cmmExecuteProce dure = new SqlCommand( "dbo.uspTest05" , cnnTheConnectio n );
cmmExecuteProce dure.CommandTyp e = CommandType.Sto redProcedure;

cnnTheConnectio n.Open();

dtsTablas = new DataSet();
dtsTablas.ReadX ml( cmmExecuteProce dure.ExecuteXml Reader(),
XmlReadMode.Fra gment );

cnnTheConnectio n.Close();

dtgResultados.D ataSource = 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( cmmExecuteProce dure.ExecuteXml Reader() )

?

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

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

dtsResults = new DataSet();
while ( !xrdResults.EOF )
{
dtsResults.Read Xml( 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.Move ToContent() to avoid any possible error?

Thanks in advance,

Frank
"John Francisco Williams" <Cu******@e-ciety.com> wrote in message
news:eC******** ******@TK2MSFTN GP12.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 cmmExecuteProce dure;
SqlConnection cnnTheConnectio n ;
DataSet dtsTablas ;

cnnTheConnectio n = new SqlConnection( strConnectionSt ring );

cmmExecuteProce dure = new SqlCommand( "dbo.uspTest04" , cnnTheConnectio n );
cmmExecuteProce dure.CommandTyp e = CommandType.Sto redProcedure;

cnnTheConnectio n.Open();

dtsTablas = new DataSet();
dtsTablas.ReadX ml( cmmExecuteProce dure.ExecuteXml Reader() );

cnnTheConnectio n.Close();

dtgResultados.D ataSource = 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 cmmExecuteProce dure;
SqlConnection cnnTheConnectio n ;
DataSet dtsTablas ;

cnnTheConnectio n = new SqlConnection( strConnectionSt ring );

cmmExecuteProce dure = new SqlCommand( "dbo.uspTest05" , cnnTheConnectio n );
cmmExecuteProce dure.CommandTyp e = CommandType.Sto redProcedure;

cnnTheConnectio n.Open();

dtsTablas = new DataSet();
dtsTablas.ReadX ml( cmmExecuteProce dure.ExecuteXml Reader(),
XmlReadMode.Fra gment );

cnnTheConnectio n.Close();

dtgResultados.D ataSource = 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( cmmExecuteProce dure.ExecuteXml Reader() )

?

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******** ******@TK2MSFTN GP12.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****@suespam mers.org> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
"John Francisco Williams" <Cu******@e-ciety.com> wrote in message
news:eC******** ******@TK2MSFTN GP12.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
2609
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 experimenting a bit with what I need to do this and have the following code snippet. But first if I pass the assembly name and type to Activator.CreateInstance() it always fails. However if I walk my assembly and get a type value, the call to...
7
5760
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 read. But when I did thiss I was told datasets were the way to go, but needs an array, prefer typed as were changing it. Here is the current code: (shortened for readability) public class WebService1{
4
3931
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 record from the db and then display for the user: oleDbConnection1.Open();
4
5071
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() drow("field1") = data for field 1 and so forth ds.tables(0).rows.add(drow) cmdBld = New SqlCommandBuilder(mySqlDataAdapter)
5
4737
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 the updated data set back. I suspect this is also simple but it eludes me. I have: Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim Conn As System.Data.OleDb.OleDbConnection
0
1269
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 believe the difference in speed! However, the asynch operation fails sometimes, despite of the fact that it works most of the time. I am really at a loss how to fix this sporadic and erratic behavior. This is a web application developed with...
1
1819
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 of the two varaibles and place it into a label on an .aspx page. Basically, MyGrossSales = GrossSales from query
1
2411
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 to buy from the datagrid. User can select books using checkboxes in the datagrid. The selected books are stored in a session variable name session("temp") which is a dataset type.After storing dataset in session (in bold letters),user will...
0
1989
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 to buy from the datagrid. User can select books using checkboxes in the datagrid. The selected books are stored in a session variable name session("temp") which is a dataset type.After storing dataset in session (in bold letters),user will...
0
8145
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8095
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8556
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8236
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8410
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7030
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5526
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4037
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2541
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.