.NETGURU
Unresolved: Dumb Question, I'm Sure
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngxml' list.


Little, Ambrose
I posted a few days ago about how to perform a FOR XML query from SQL and
get the entire document into a string. Dan W. helped me by saying use the
MoveToContent and ReadOuterXml methods, but that appears to only get the
first record. I need to have a well-formed XML document from this, so I
guess I need to add a root element or something. I have a deadline, so I
don't have time to read all the books on the subject. So if someone could
please just tell me step-by-step how to do this, I would REALLY appreciate
it.

TIA,

--Ambrose

******************************************************************************
The Company reserves the right to amend statements
made herein in the event of a mistake. Unless expressly
stated herein to the contrary, only agreements in writing signed
by an authorized officer of the Company may be enforced against it.
*******************************************************************************

Reply to this message...
 
    
Tim Curtin
Hope this helps: Change the "Load()" to LoadXML(strXML) in the code and
modify where appropriate. I posted this to another thread and it works well:
dim oDoc as New XmlDataDocument
dim item as XmlElement
dim items as XmlNodeList
dim con as New
SqlConnection(ConfigurationSettings.AppSettings("ConString").ToString())
con.Open
dim da as New SqlDataAdapter
odoc.Load(ConfigurationSettings.AppSettings("xmlfile").ToString())
items = odoc.SelectNodes("//tabCatalog")
dim cmd as New SqlCommand
with cmd
.CommandText="pSaveCatalogItem"
.CommandType=CommandType.StoredProcedure
.Connection=con
.Parameters.Add(new SqlParameter("@ID", sqldbtype.Int))
.Parameters.Add(new
SqlParameter("@Desc1",sqldbtype.VarChar,200))
.Parameters.Add(new SqlParameter("@Price", SqlDbType.Money ))
.Parameters.Add(new
SqlParameter("@ImageFileName",sqldbtype.VarChar,100))
.Parameters.Add(new SqlParameter("@PriceB4Disc"
,sqldbtype.money,8))
.Parameters.Add(new SqlParameter("@CatalogID",sqldbtype.Int))
for each item in items

.Parameters("@ID").Value=item.SelectSingleNode("ID").InnerText

.Parameters("@Desc1").value=item.SelectSingleNode("Desc1").InnerText

.Parameters("@Price").Value=item.SelectSingleNode("Price").InnerText

.Parameters("@ImageFileName").Value=item.SelectSingleNode("ImageFilename").InnerText

.Parameters("@PriceB4Disc").Value=item.SelectSingleNode("PriceB4Disc").InnerText

.Parameters("@CatalogID").Value=item.SelectSingleNode("CatalogID").InnerText
.ExecuteNonQuery
i+=1
Next
end with
cmd=nothing
con.Close
con=nothing
response.Write(i & " XML Records were inserted")

Here is the XML:
<?xml version="1.0" encoding="UTF-8"?>
<XMLCatalog>
<tabCatalog>
<ID>205753</ID>
<Desc1>ANANDATSE DOHI (CASSETTE)</Desc1>
<Price>9.95</Price>
<ImageFilename>thumbs/t105120.jpg</ImageFilename>
<PriceB4Disc>0</PriceB4Disc>
<CatalogID>1</CatalogID>
</tabCatalog>
<tabCatalog>
     <ID>205755</ID>
     <Desc1>Test CD</Desc1>
     <Price>911.95</Price>
     <ImageFilename>thumbs/t105125.jpg</ImageFilename>
     <PriceB4Disc>0</PriceB4Disc>
     <CatalogID>2</CatalogID>
</tabCatalog>
</XMLCatalog>

[Original message clipped]

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com

Reply to this message...
 
    
Little, Ambrose
Tim,

Thank you for this. Unfortunately, I wasn't clear enough when I posted my
question. I'm selecting data *from* SQL Server using a FOR XML AUTO query
to return XML. Here's my current "test" code:

System.Data.SqlClient.SqlCommand comm = new SqlCommand();
comm.Connection = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["EPRO_D
B_ConnString"]);
comm.CommandText = "EXEC dbo.GetDMTransactionsAsXML '6/26/02'";
comm.Connection.Open();

XmlReader xr = comm.ExecuteXmlReader();
xr.MoveToContent();
                
textBox1.Text = xr.ReadOuterXml();

Right now, this code is only reaturn the first record (transaction) as XML.
I need to get all of the transactions returned into a well-formed XML
document to pass to Biztalk. How could I modify the above to get this?

Many thanks!

--Ambrose

[Original message clipped]

******************************************************************************
The Company reserves the right to amend statements
made herein in the event of a mistake. Unless expressly
stated herein to the contrary, only agreements in writing signed
by an authorized officer of the Company may be enforced against it.
*******************************************************************************

Reply to this message...
 
 
System.Configuration.ConfigurationSettings
System.Data.CommandType
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter
System.Data.SqlClient.SqlParameter
System.Data.SqlDbType
System.Xml.XmlDataDocument
System.Xml.XmlElement
System.Xml.XmlNodeList
System.Xml.XmlReader




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification